forked from majnemer/davesdots
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vimrc
393 lines (333 loc) · 10.3 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
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
" vimrc
" Current author: David Majnemer
" Original author: Saleem Abdulrasool <[email protected]>
" 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 ($ANSWERBACK !=# "PuTTY")
if (&termencoding == "" && (&term =~ "xterm" || &term =~ "putty")) || (&term =~ "rxvt-unicode") || (&term =~ "screen")
set termencoding=utf-8
endif
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
if has('smartindent')
set smartindent " Indent next line based on current line
endif
"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 smartcase " ...except when we don't want it
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 number " Show line numbers
set colorcolumn=120
set diffopt+=iwhite
" ---- Filetypes ----
if has('syntax')
syntax on
endif
if has('eval')
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
if has('viminfo')
autocmd BufReadPost *
\ if line("'\"") > 0 && line("'\"") <= line("$") |
\ exe "normal g`\"" |
\ endif
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=%<%F\ %r[%{&ff}]%y%m\ %=\ Line\ %l\/%L\ Col:\ %v\ (%P)
endif
" Enable modelines only on secure vim
if (v:version == 603 && has("patch045")) || (v:version > 603)
set modeline
set modelines=3
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:twilight256:desert")
elseif &t_Co == 256
call LoadColorScheme("wombat:twilight256:inkpot")
elseif &t_Co == 88
call LoadColorScheme("wombat:zellner")
else
call LoadColorScheme("desert:darkblue: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
nmap <C-]> :call GoDefinition()<CR>
endif
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()
autocmd BufNewFile,BufRead *.mm set filetype=noweb
autocmd BufNewFile,BufRead *.scala set filetype=scala
autocmd BufNewFile,BufRead *.proto set filetype=proto
autocmd BufNewFile,BufRead *.atomo set filetype=atomo
autocmd BufNewFile,BufRead *.atomo setlocal expandtab tabstop=2 shiftwidth=2 softtabstop=2 commentstring=--\ %s
endif
" make tab reindent in normal mode
autocmd FileType c,cpp,cs,java nmap <Tab> =0<CR>
endif
" Append modeline after last line in buffer.
" Use substitute() (not printf()) to handle '%%s' modeline in LaTeX files.
if has('eval')
fun! AppendModeline()
let save_cursor = getpos('.')
let append = ' vim: set ts='.&tabstop.' sw='.&shiftwidth.' tw='.&textwidth.': '
$put =substitute(&commentstring, '%s', append, '')
call setpos('.', save_cursor)
endfun
nnoremap <silent> <Leader>ml :call AppendModeline()<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>
" stolen from auctex.vim
if has('eval')
fun! EmacsKill()
if col(".") == strlen(getline(line(".")))+1
let @" = "\<CR>"
return "\<Del>"
else
return "\<C-O>D"
endif
endfun
endif
" some emacs-isms are OK
map! <C-a> <Home>
map <C-a> <Home>
map! <C-e> <End>
map <C-e> <End>
imap <C-f> <Right>
imap <C-b> <Left>
map! <M-BS> <C-w>
map <C-k> d$
if has('eval')
inoremap <buffer> <C-K> <C-R>=EmacsKill()<CR>
endif
" w!! for sudo w!
"cmap w!! w !sudo tee % >/dev/null
" clear search
"nnoremap <esc> :noh<return><esc>
" 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 <C-[>[H <Home>
map <C-[>[U <End>
elseif (&term =~ "^sun")
map <C-?> <DEL>
map! <C-?> <DEL>
elseif (&term !~ "cons")
map <C-?> <BS>
map! <C-?> <BS>
endif
if (&term =~ "^xterm")
map <C-[>[H <Home>
map! <C-[>[H <Home>
map <C-[>[F <End>
map! <C-[>[F <End>
map <C-[>[5D <C-Left>
map! <C-[>[5D <C-Left>
map <C-[>[5C <C-Right>
map! <C-[>[5C <C-Right>
endif
" Terminal.app does not support back color erase
if ($TERM_PROGRAM ==# "Apple_Terminal" && $TERM_PROGRAM_VERSION <= 273)
set t_ut=
endif
" Python specific stuff
if has('eval')
let python_highlight_all = 1
let python_slow_sync = 1
endif
" ---- OmniCpp ----
if v:version >= 700
if has('autocmd')
autocmd InsertLeave * if pumvisible() == 0|pclose|endif
endif
set completeopt=menu,menuone,longest
let OmniCpp_MayCompleteDot = 1 " autocomplete with .
let OmniCpp_MayCompleteArrow = 1 " autocomplete with ->
let OmniCpp_MayCompleteScope = 1 " autocomplete with ::
let OmniCpp_SelectFirstItem = 2 " select first item (but don't insert)
let OmniCpp_NamespaceSearch = 2 " search namespaces in this and included files
let OmniCpp_ShowPrototypeInAbbr = 1 " show function prototype (i.e. parameters) in popup window
map <C-F12> :!$HOME/bin/ctags -R --c++-kinds=+p --fields=+iaS --extra=+q .<CR><CR>
" add current directory's generated tags file to available tags
set tags+=./tags
endif
set t_RV=