-
Notifications
You must be signed in to change notification settings - Fork 0
/
vimrc
311 lines (260 loc) · 7.83 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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
" vimrc
" Main, Original author: Saleem Abdulrasool <[email protected]>
" Trivial modifications: David Majnemer
" vim: set ts=3 sw=3 et nowrap:
if has ('multi_byte') " Make sure we have unicode support
scriptencoding utf-8 " This file is in UTF-8
" ---- Terminal Setup ----
if (&termencoding == "" && (&term =~ "xterm" || &term =~ "putty")) || (&term =~ "rxvt-unicode")
set termencoding=utf-8
endif
set encoding=utf-8 " Default encoding should always be UTF-8
endif
" ---- General Setup ----
set nocompatible " Don't emulate vi's limitations
set tabstop=4 " 4 spaces for tabs
set shiftwidth=4 " 4 spaces for indents
set smarttab " Tab next line based on current line
"set expandtab " Spaces for indentation
set autoindent " Automatically indent next line
set smartindent " Indent next line based on current line
"set linebreak " Display long lines wrapped at word boundaries
set incsearch " Enable incremental searching
set hlsearch " Highlight search matches
set ignorecase " Ignore case when searching
set infercase " Attempt to figure out the correct case
set showfulltag " Show full tags when doing completion
set virtualedit=block " Only allow virtual editing in block mode
set lazyredraw " Lazy Redraw (faster macro execution)
set wildmenu " Menu on completion please
set wildmode=longest,full " Match the longest substring, complete with first
set wildignore=*.o,*~ " Ignore temp files in wildmenu
set scrolloff=3 " Show 3 lines of context during scrolls
set sidescrolloff=2 " Show 2 columns of context during scrolls
set backspace=2 " Normal backspace behavior
"set textwidth=80 " Break lines at 80 characters
set hidden " Allow flipping of buffers without saving
set noerrorbells " Disable error bells
set visualbell " Turn visual bell on
set t_vb= " Make the visual bell emit nothing
set showcmd " Show the current command
set diffopt+=iwhite
" ---- Filetypes ----
if has('syntax')
syntax on
endif
if has('osfiletype')
filetype on " Detect filetype by extension
filetype indent on " Enable indents based on extensions
filetype plugin on " Load filetype plugins
endif
" ---- Folding ----
if has('eval')
fun! WideFold()
if winwidth(0) > 90
setlocal foldcolumn=1
else
setlocal foldcolumn=0
endif
endfun
let g:detectindent_preferred_expandtab = 0
let g:detectindent_preferred_indent = 4
fun! <SID>DetectDetectIndent()
try
:DetectIndent
catch
endtry
endfun
endif
if has('autocmd')
autocmd BufEnter * :call WideFold()
if has('eval')
autocmd BufReadPost * :call s:DetectDetectIndent()
endif
autocmd BufReadPost *
\ if line("'\"") > 0 && line("'\"") <= line("$") |
\ exe "normal g`\"" |
\ endif
endif
" ---- Spelling ----
if (v:version >= 700)
set spelllang=en_us " US English Spelling please
" Toggle spellchecking with F10
nmap <silent> <F10> :silent set spell!<CR>
imap <silent> <F10> <C-O>:silent set spell!<CR>
endif
" Display a pretty statusline if we can
if has('title')
set title
endif
set laststatus=2
set shortmess=atI
if has('statusline')
set statusline=Editing:\ %r%t%m\ %=Location:\ Line\ %l/%L\ \ Col:\ %c\ (%p%%)
endif
" Enable modelines only on secure vim
if (v:version == 603 && has("patch045")) || (v:version > 603)
set modeline
else
set nomodeline
endif
" Shamelessly stolen from Ciaran McCreesh <[email protected]>
if has('eval')
fun! LoadColorScheme(schemes)
let l:schemes = a:schemes . ":"
while l:schemes != ""
let l:scheme = strpart(l:schemes, 0, stridx(l:schemes, ":"))
let l:schemes = strpart(l:schemes, stridx(l:schemes, ":") + 1)
try
exec "colorscheme" l:scheme
break
catch
endtry
endwhile
endfun
if has("gui_running")
call LoadColorScheme("wombat:desert")
elseif &t_Co == 256
call LoadColorScheme("wombat:inkpot")
elseif &t_Co == 88
call LoadColorScheme("wombat:zellner")
else
call LoadColorScheme("zellner")
endif
endif
" Show trailing whitespace visually
" Shamelessly stolen from Ciaran McCreesh <[email protected]>
if (&termencoding == "utf-8") || has("gui_running")
if v:version >= 700
set list listchars=tab:»·,trail:·,extends:…,nbsp:‗
else
set list listchars=tab:»·,trail:·,extends:…
endif
else
if v:version >= 700
set list listchars=tab:>-,trail:.,extends:>,nbsp:_
else
set list listchars=tab:>-,trail:.,extends:>
endif
endif
if has('mouse')
" Dont copy the listchars when copying
set mouse=nvi
endif
if has('autocmd')
" always refresh syntax from the start
autocmd BufEnter * syntax sync fromstart
" subversion commit messages need not be backed up
autocmd BufRead svn-commit.tmp :setlocal nobackup
" mutt does not like UTF-8
autocmd BufRead,BufNewFile *
\ if &ft == 'mail' | set fileencoding=iso8859-1 | endif
" fix up procmail rule detection
autocmd BufRead procmailrc :setfiletype procmail
endif
" ---- cscope/ctags setup ----
if has('cscope') && executable('cscope') == 1
" Search cscope and ctags, in that order
set cscopetag
set cscopetagorder=0
set nocsverb
if filereadable('cscope.out')
cs add cscope.out
endif
set csverb
endif
" ---- Key Mappings ----
" improved lookup
if has('eval')
fun! GoDefinition()
let pos = getpos(".")
normal! gd
if getpos(".") == pos
exe "tag " . expand("<cword>")
endif
endfun
endif
nmap <C-]> :call GoDefinition()<CR>
if has('autocmd')
" Shortcuts
if has('eval')
fun! <SID>cabbrev()
iab #i #include
iab #I #include
iab #d #define
iab #D #define
iab #e #endif
iab #E #endif
endfun
autocmd FileType c,cpp :call <SID>cabbrev()
endif
" make tab reindent in normal mode
autocmd FileType c,cpp,cs,java nmap <Tab> =0<CR>
endif
" tab indents selection
vmap <silent> <Tab> >gv
" shift-tab unindents
vmap <silent> <S-Tab> <gv
" Page using space
noremap <Space> <C-F>
" shifted arrows are stupid
inoremap <S-Up> <C-O>gk
noremap <S-Up> gk
inoremap <S-Down> <C-O>gj
noremap <S-Down> gj
" Y should yank to EOL
map Y y$
" vK is stupid
vmap K k
" :W and :Q are annoying
if has('user_commands')
command! -nargs=0 -bang Q q<bang>
command! -nargs=0 -bang W w<bang>
command! -nargs=0 -bang WQ wq<bang>
command! -nargs=0 -bang Wq wq<bang>
endif
" just continue
nmap K K<cr>
" tabs
map <C-S-Tab> :tabprevious<CR>
imap <C-S-Tab> <Esc>:tabprevious<CR>i
map <S-Left> :tabprevious<CR>
imap <S-Left> <Esc>:tabprevious<CR>i
map <C-Tab> :tabnext<CR>
imap <C-Tab> <Esc>:tabnext<CR>i
map <S-Right> :tabnext<CR>
imap <S-Right> <Esc>:tabnext<CR>i
nmap <C-t> :tabnew<CR>
imap <C-t> <Esc>:tabnew<CR>i
" Disable q and Q
map q <Nop>
map Q <Nop>
" Toggle numbers with F12
nmap <silent> <F12> :silent set number!<CR>
imap <silent> <F12> <C-O>:silent set number!<CR>
noremap <silent> <F4> :set hls!<CR>
" Don't force column 0 for #
inoremap # X<BS>#
" Always map <C-h> to backspace
" Both interix and cons use C-? as forward delete,
" besides those two exceptions, always set it to backspace
" Also let interix use ^[[U for end and ^[[H for home
map <C-h> <BS>
map! <C-h> <BS>
if (&term =~ "interix")
map <C-?> <DEL>
map! <C-?> <DEL>
map [H <Home>
map [U <End>
elseif (&term =~ "^sun")
map <C-?> <DEL>
map! <C-?> <DEL>
elseif (&term !~ "cons")
map <C-?> <BS>
map! <C-?> <BS>
endif
" Python specific stuff
if has('eval')
let python_highlight_all = 1
let python_slow_sync = 1
endif