/
vimrc
146 lines (121 loc) · 3.43 KB
/
vimrc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
set nocompatible
filetype off
silent! call pathogen#infect()
silent! call pathogen#helptags()
filetype plugin indent on
syntax on
let mapleader = ","
" Disable up and down arrow keys and some other insert mode navigation
inoremap <Left> <NOP>
inoremap <Down> <NOP>
inoremap <Up> <NOP>
inoremap <Right> <NOP>
inoremap <Home> <NOP>
inoremap <End> <NOP>
" Move by screen line instead of text line.
" Relevant when text is wrapped.
nnoremap j gj
nnoremap k gk
" Disable ex mode, which I have literally never used
nnoremap Q <nop>
" Disable command line history. This often pops up when trying to quit
" with :q but typing q: instead.
nnoremap q: <nop>
" Convenient insert mode save. The idea here is to press j and k at
" the same time without worrying about which of j or k is actually
" pressed first.
inoremap jk <ESC>:w<Enter>
inoremap kj <ESC>:w<Enter>
" Copy to system clipboard
noremap <leader>y "+y
" Paste from system clipboard
noremap <leader>p "+p
noremap <leader>P "+P
" Basics
set shell=/bin/bash
set autowrite
set backspace=indent,eol,start
" Fixes 'crontab: temp file must be edited in place' on Mac OS
set backupskip+=/private/tmp/*
set cursorline
set encoding=utf-8
set foldlevel=99
set foldmethod=indent
set hidden
set mouse=a
set mousehide " Hide pointer while typing
set ruler
set showcmd
set showmode
set showtabline=1
set termguicolors
set wildmenu
set wildmode=list:longest
" Search
nnoremap / /\v
vnoremap / /\v
set gdefault
set hlsearch
set incsearch
set showmatch
set smartcase
nnoremap <leader><space> :noh<cr>
" Text formatting
set autoindent
if exists('&colorcolumn')
set colorcolumn=+1
endif
highlight ColorColumn ctermbg=7
set expandtab
set formatoptions=tcrqnl1
if v:version >= 703
set formatoptions+=j
endif
set list
set listchars=tab:»\ ,trail:·
set shiftwidth=4
set softtabstop=4
set textwidth=99
function <SID>strip_trailing_whitespace()
let l = line(".")
let c = col(".")
let s = @/
%s/\s\+$//e
call cursor(l, c)
let @/ = s
endfun
noremap <leader>s :call <SID>strip_trailing_whitespace()<CR>
augroup vimrc
autocmd!
autocmd FocusLost * :wa
autocmd FileType css setlocal sw=2 sts=2
autocmd FileType html setlocal sw=2 sts=2
autocmd FileType javascript setlocal sw=2 sts=2
autocmd FileType json setlocal sw=2 sts=2
autocmd FileType markdown setlocal sw=2 sts=2 tw=72
autocmd FileType text setlocal sw=2 sts=2 tw=72
autocmd FileType yaml setlocal sw=2 sts=2 tw=79
autocmd BufRead,BufNewFile *.commit set filetype=gitcommit
autocmd FileType gitcommit setlocal sw=4 sts=4 tw=72
autocmd BufRead,BufNewFile *.mako set filetype=mako
autocmd FileType mako setlocal sw=2 sts=2
autocmd BufRead,BufNewFile ~/.bashrc.d/*.rc set filetype=sh
autocmd BufRead,BufNewFile CHANGELOG set filetype=rst
" Python files:
" - Don't auto-wrap code
" - Make comments wrap at column 72 (works with format option c)
" - Display right margin in column 100
autocmd FileType python setlocal fo-=t tw=72 cc=88
" Set default completion function only if one isn't already set on the
" file.
autocmd FileType *
\ if &omnifunc == "" |
\ setlocal omnifunc=syntaxcomplete#Complete |
\ endif
augroup END
" Supertab
let g:SuperTabDefaultCompletionType = "context"
" NERDCommenter
" Make comment toggling easier
nmap <silent> <leader>/ <leader>c<space>
xmap <silent> <leader>/ <leader>c<space>