-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvimrc
More file actions
546 lines (463 loc) · 17.9 KB
/
Copy pathvimrc
File metadata and controls
546 lines (463 loc) · 17.9 KB
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
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
" Vundle and bundles configuration
source ~/dotvim/bundles.vim
syntax on
syntax spell toplevel
set history=200
" Map leader key
let mapleader = ","
noremap \ ,
" Map star key
noremap * *``
" Clipboard
vnoremap <C-c> "*y
vnoremap <C-c> "+y
set nocp
filetype indent plugin on " required!
" Set gnuplot filetype
autocmd BufNewFile,BufRead *.gnu set filetype=gnuplot
" Exclude paths in file name completeion
" set wildignore+=/nls/p/*/
inoremap <leader>fp <C-R>=expand("%:p:h")<CR>
inoremap <leader>fn <C-R>=expand("%:p")<CR>
" Directory setup
set backupdir=~/dotvim/backup_files/
set directory=~/dotvim/swap_files/
" set undodir=~/dotvim/undo_files/
" Adjust comment style
autocmd FileType c,cpp,cs,java setlocal commentstring=//\ %s
autocmd FileType matlab setlocal commentstring=%\ %s
autocmd FileType c,cpp,cs,java,perl setlocal noexpandtab
" Snips UltiSnips
" Trigger configuration. Do not use <tab> if you use https://github.com/Valloric/YouCompleteMe.
let g:UltiSnipsExpandTrigger="<c-s>"
let g:UltiSnipsJumpForwardTrigger="<c-g>"
let g:UltiSnipsJumpBackwardTrigger="<c-b>"
let g:UltiSnipsSnippetDirectories=["UltiSnips", "myUltiSnippets"]
let g:snips_author="Yousef El-Kurdi"
let g:snips_instit="IBM Research"
" If you want :UltiSnipsEdit to split your window.
let g:UltiSnipsEditSplit="vertical"
" Notes file type
au BufNewFile,BufRead *.notes set filetype=conf
" Syntax ranges for notes filetypes
au FileType conf,text call SyntaxRange#Include('<sh>', '</sh>', 'sh', 'NonText')
au FileType conf,text call SyntaxRange#Include('<c>', '</c>', 'c', 'NonText')
au FileType conf,text call SyntaxRange#Include('<cpp>', '</cpp>', 'cpp', 'NonText')
" vim-latexsuite
set grepprg=grep\ -nH\ $*
let g:tex_flavor='latex'
let g:Tex_UseMakefile=1
let g:Tex_DefaultTargetFormat='pdf'
"let g:Tex_CompileRule_pdf='pdflatex -interaction=nonstopmode $*'
"let g:Tex_ViewRule_pdf = 'xpdf -remote 127.0.0.1'
" Set the target format to pdf.
let g:Tex_MultipleCompileFormats='pdf,div,ps'
" Set the warning messages to ignore.
let g:Tex_IgnoredWarnings =
\"Underfull\n".
\"Overfull\n".
\"specifier changed to\n".
\"You have requested\n".
\"Missing number, treated as zero.\n".
\"There were undefined references\n".
\"Citation %.%# undefined\n".
\'LaTeX Font Warning:'"
" This number N says that latex-suite should ignore the first N of the above.
let g:Tex_IgnoreLevel = 8
let g:tex_indent_brace = 0
let g:Tex_GotoError = 0
let g:Tex_GotoError = 0 " Does not work because of quickfix
" TIP: if you write your \label's as \label{fig:something}, then if you
" type in \ref{fig: and press Ctrl-N you will automatically cycle through
" all the figure labels. Very useful!
set iskeyword+=:
" autocomple pop
let g:acp_behaviorKeywordLength = 5
" astyle
if !exists("g:formatprg_c") | let g:formatprg_c = "astyle" | endif
if !exists("g:formatprg_args_expr_c") && !exists("g:formatprg_args_c")
let g:formatprg_args_expr_c = '"--style=allman --mode=c --pad-oper --convert-tabs --indent=spaces=4 --pad-header --max-code-length=80 --align-pointer=type --lineend=linux --suffix=none"'
endif
if !exists("g:formatprg_cpp") | let g:formatprg_cpp = "astyle" | endif
if !exists("g:formatprg_args_expr_cpp") && !exists("g:formatprg_args_cpp")
let g:formatprg_args_expr_cpp = '"--style=allman --mode=c --pad-oper --convert-tabs --indent=spaces=4 --pad-header --max-code-length=80 --align-pointer=type --lineend=linux --suffix=none"'
endif
let g:EclimCompletionMethod = 'omnifunc'
"Omnicomplete
let use_omnicomplete = 1
if use_omnicomplete
if v:version >= 700
set omnifunc=syntaxcomplete#Complete " override built-in C omnicomplete with C++ OmniCppComplete plugin
let OmniCpp_DefaultNamespaces = ["std", "_GLIBCXX_STD"]
let OmniCpp_DisplayMode = 1
let OmniCpp_GlobalScopeSearch = 1
let OmniCpp_MayCompleteArrow = 1 " autocomplete after ->
let OmniCpp_MayCompleteDot = 1 " autocomplete after .
let OmniCpp_MayCompleteScope = 1 " autocomplete after ::
let OmniCpp_NamespaceSearch = 1
let OmniCpp_SelectFirstItem = 1 "select first item in pop-up
let OmniCpp_ShowAccess = 1 "show access in pop-up
let OmniCpp_ShowPrototypeInAbbr = 1 "show prototype in pop-up
let OmniCpp_ShowScopeInAbbr = 0 "do not show namespace in pop-up
" automatically open and close the popup menu / preview window
au CursorMovedI,InsertLeave * if pumvisible() == 0|silent! pclose|endif
set completeopt=menuone,menu,longest,preview
"set completeopt=menuone,menu,longest
" Modify colors
"highlight clear
"highlight Pmenu ctermfg=0 ctermbg=2
"highlight PmenuSel ctermfg=0 ctermbg=7
"highlight PmenuSbar ctermfg=7 ctermbg=0
"highlight PmenuThumb ctermfg=0 ctermbg=7
endif
" ctags build map
" function! UpdateTags()
" execute ":!ctags -R --languages=C++ --c++-kinds=+p --fields=+iaS --extra=+q -f .tags *"
" echohl StatusLine | echo "C/C++ tag updated" | echohl None
" endfunction
" nnoremap <C-F12> :call UpdateTags() <CR>
endif
" Rename current buffer
function! RenameFile()
let old_name = expand('%')
let new_name = input('New file name: ', expand('%'), 'file')
if new_name != '' && new_name != old_name
exec ':saveas ' . new_name
exec ':silent !rm ' . old_name
redraw!
endif
endfunction
map <leader>n :call RenameFile()<cr>
" Map compile keys
autocmd FileType c,cpp nmap <F9> :SCCompile -o %<.out<cr>
autocmd FileType c,cpp nmap <F10> :SCCompileRun -o %<.out<cr>
"Supertab
let g:SuperTabDefaultCompletionType = 'context'
"Syntastic
"let g:syntastic_c_checkers=['gcc']
"let g:syntastic_cpp_checkers=['gcc']
"let g:syntastic_check_on_open=1
"let g:syntastic_enable_signs=1
" colorshemes
" colorscheme desert
" colorscheme wasabi256
colorscheme adaryn
" colorscheme wombat256mod
" colorscheme wombat256
set bg=dark
" scrolloff
set so=5
" Use the same symbols as TextMate for tabstops and EOLs
set listchars=tab:▸\ ,eol:¬
"Invisible character colors
highlight NonText guifg=#4a4a59
highlight SpecialKey guifg=#4a4a59
" cmdline-completion
set wildmode=longest,list " This would emulate the typical shell completion
" case setupe
set ignorecase
set smartcase
set infercase
" set noignorecase infercase
" Thesaurus
" moby uses phrases witch contain spaces so account for them
" set thesaurus+=~/dotvim/thesaurus/mthesaur.nix
" Online Thesaurus
let g:online_thesaurus_map_keys = 0
nnoremap <leader>tt :OnlineThesaurusCurrentWord<CR>
" Persistent yank
vnoremap p pgvy
" Indentation
set ts=4 " Activating this misses up indentation for some code files
set sw=2
set sts=4
set expandtab " conversion of actual tab character (ctrl-v) to spaces
set smarttab
set autoindent " turns it on
set smartindent " does the right thing (mostly) in programs
" Text wrapping
"set linebreak nolist " break lines cleanly at word boundaries
set wrap
set linebreak
set nolist
"set showbreak= \ \
set showbreak=…
" Searching
set hlsearch
set incsearch
set wrapscan " searches wrap bottom to top of file
" Dictionary
set dictionary+=/usr/share/dict/words
" Spelling
set spellfile=~/dotvim/dict.add
au BufNewFile,BufRead,BufEnter *.tex setlocal spell spelllang=en_us
au BufNewFile,BufRead,BufEnter *.txt setlocal spell spelllang=en_us
" Visual indicators
nnoremap <Leader>H :call<SID>LongLineHLToggle()<cr>
hi OverLength ctermbg=none cterm=none
match OverLength /\%>80v/
fun! s:LongLineHLToggle()
if !exists('w:longlinehl')
let w:longlinehl = matchadd('ErrorMsg', '.\%>80v', 0)
echo "Long lines highlighted"
else
call matchdelete(w:longlinehl)
unl w:longlinehl
echo "Long lines unhighlighted"
endif
endfunction
" Activating highlights indicator after column 80
au BufWinEnter *.{c,cc,cpp,h,hpp} let w:longlinehl = matchadd('ErrorMsg', '.\%>80v', 0)
" Add line numbers per line
set number
" Matching characters
" Closing braces
" inoremap { {}<Left>
" inoremap {<CR> {<CR>}<Esc>O
" inoremap {{ {
" inoremap {} {}
" inoremap ( ()<Left>
" inoremap <expr> ) strpart(getline('.'), col('.')-1, 1) == ")" ? "\<Right>" : ")"
" inoremap <expr> } strpart(getline('.'), col('.')-1, 1) == "}" ? "\<Right>" : "}"
" inoremap <expr> " strpart(getline('.'), col('.')-1, 1) == "\"" ? "\<Right>" : "\"\"\<Left>"
" Folding
set foldmethod=syntax
nnoremap <Space> za
vnoremap <Space> za
nnoremap zO zCzO
"Modify default fold for gitcommit
autocmd Syntax gitcommit normal zR
autocmd FileType gitcommit set spell spelllang=en
"Default fold for text files
autocmd FileType text set foldmethod=indent
function! s:insert_gates()
let gatename = substitute(toupper(expand("%:t")), "\\.", "_", "g")
execute "normal! i#ifndef " . gatename
execute "normal! o#define " . gatename . " "
execute "normal! Go#endif /* " . gatename . " */"
normal! kk
endfunction
autocmd BufNewFile *.{h,hpp} call <SID>insert_gates()
" http://vim.wikia.com/wiki/Keep_folds_closed_while_inserting_text
autocmd InsertEnter * if !exists('w:last_fdm') | let w:last_fdm=&foldmethod | setlocal foldmethod=manual | endif
autocmd InsertLeave,WinLeave * if exists('w:last_fdm') | let &l:foldmethod=w:last_fdm | unlet w:last_fdm | endif
" Key mapings
" Indent all
" Exit insert mode
"vmap <D-j> gj
"vmap <D-k> gk
"vmap <D-4> g$
"vmap <D-6> g^
"vmap <D-0> g^
"nmap <D-j> gj
"nmap <D-k> gk
"nmap <D-4> g$
"nmap <D-6> g^
"nmap <D-0> g^
" map <F2> mzgg=G`z<CR>
noremap <F2> :Autoformat<CR><CR>
vmap <space> <C-w>
" Inserting a line above in normal mode
map <S-Enter> O<Esc>
" For local variable renaming
nnoremap gr gd[{V%:s/<C-R>///gc<left><left><left>
" For global variable renaming
nnoremap gR gD:%s/<C-R>///gc<left><left><left>}
"nnoremap <silent><Leader><C-]> <C-w><C-]><C-w>T
map <C-\> :tab split<CR>:exec("tag ".expand("<cword>"))<CR>
map <A-]> :vsp <CR>:exec("tag ".expand("<cword>"))<CR>
" Highilighting status line based on mode
" first, enable status line always
set laststatus=2
"set statusline=
"set statusline+=\[%n] "buffernr
"set statusline+=\ %<%f\ "file for File+path use: F
"set statusline+=\ \ %m%r%w\ \ "Modified? Readonly?
"set statusline+=\ %y\ "FileType
"set statusline+=\ %{''.(&fenc!=''?&fenc:&enc).''}\ "Encoding
"set statusline+=\ %{(&bomb?\",BOM\":\"\")}\ "Encoding2
"set statusline+=\ %{&ff}\ "FileFormat (dos/unix..)
"set statusline+=\ %{&spelllang}\ %{HighlightSearch()}\ "Spellanguage & Highlight on?
"set statusline+=\ %=\ Line:%l/%L\ (%03p%%)\ "Linenumber/total (%)
"set statusline+=\ col:%03c\ "Colnr
set statusline=
set statusline+=\[%n] "buffernr
set statusline+=\ %<%f\ "file for File+path use: F
set statusline+=\%{fugitive#statusline()}\ "Git current branch
set statusline+=\ \ %m%r%w\ \ "Modified? Readonly?
set statusline+=\ %y\ "FileType
set statusline+=\ %=\ Line:%l/%L\ (%03p%%)\ "Linenumber/total (%)
set statusline+=\ col:%03c\ "Colnr
" check existence of file
function LS() range
echo system('ls -lh '.shellescape(join(getline(a:firstline, a:lastline), "\n")).'')
endfunction
function! HighlightSearch()
if &hls
return 'H'
else
return ''
endif
endfunction
"
hi User0 guifg=#ffffff guibg=#094afe ctermfg=White ctermbg=Black
hi User1 guifg=#ffdad8 guibg=#880c0e ctermfg=Black ctermbg=Black
hi User2 guifg=#000000 guibg=#F4905C ctermfg=Black ctermbg=Cyan
hi User3 guifg=#292b00 guibg=#f4f597 ctermfg=Black ctermbg=LightRed
hi User4 guifg=#112605 guibg=#aefe7B ctermfg=Black ctermbg=LightGreen
hi User5 guifg=#051d00 guibg=#7dcc7d ctermfg=Black ctermbg=Green
hi User7 guifg=#ffffff guibg=#880c0e ctermfg=White ctermbg=Blue
hi User8 guifg=#ffffff guibg=#5b7fbb ctermfg=White ctermbg=Blue
hi User9 guifg=#ffffff guibg=#810085 ctermfg=White ctermbg=Magenta
"
" now set it up to change the status line based on mode
if version >= 700
au InsertEnter * hi StatusLine term=reverse ctermfg=Yellow ctermbg=Black gui=bold guifg=Black guibg=Yellow
au InsertLeave * hi StatusLine term=reverse ctermfg=White ctermbg=Black gui=bold guifg=Black guibg=White
endif
" Loading custom vim settings for different projects
au BufNewFile,BufRead *.{c,cc,cpp,h,hpp} call CheckForCustomConfiguration()
function! CheckForCustomConfiguration()
" Check for .vim.custom in the directory containing the newly opened file
let custom_config_file = expand('%:p:h') . '/.vim.custom'
if filereadable(custom_config_file)
exe 'source' custom_config_file
endif
endfunction
" vimdiff
" ignore white spaces
if &diff
" diff mode
set diffopt+=iwhite
endif
" Gui options for gvim
" :set guioptions-=m "remove menu bar
:set guioptions-=T "remove toolbar
:set guioptions-=r "remove right-hand scroll bar
" Special file types
au BufNewFile,BufRead *.geo setf c "Set c syntax for gmsh geo files
" Only do this part when compiled with support for autocommands
if has("autocmd")
" Enable file type detection
filetype on
" Syntax of these languages is fussy over tabs Vs spaces
autocmd FileType make setlocal ts=8 sts=8 sw=8 noexpandtab
autocmd FileType yaml setlocal ts=2 sts=2 sw=2 expandtab
" Customisations based on house-style (arbitrary)
autocmd FileType html setlocal ts=2 sts=2 sw=2 expandtab
autocmd FileType css setlocal ts=2 sts=2 sw=2 expandtab
autocmd FileType javascript setlocal ts=4 sts=4 sw=4 noexpandtab
autocmd FileType tex setlocal ts=4 sts=4 sw=4 noexpandtab
" Treat .rss files as XML
autocmd BufNewFile,BufRead *.rss setfiletype xml
endif
" Set matlab file type .param in Getfem
"autocmd BufNewFile,BufRead *.param set filetype=octave
"autocmd BufNewFile,BufRead *.m set filetype=octave
autocmd BufNewFile,BufRead *.param set filetype=matlab
" Set .tag files to html filetypes
autocmd BufNewFile,BufRead *.tag set filetype=html
" Set md file types
autocmd BufNewFile,BufReadPost *.md set filetype=markdown
nnoremap <silent> <F3> :call <SID>StripTrailingWhitespaces()<CR>
function! <SID>StripTrailingWhitespaces()
" Preparation: save last search, and cursor position.
let _s=@/
let l = line(".")
let c = col(".")
" Do the business:
%s/\s\+$//e
" Clean up: restore previous search history, and cursor position
let @/=_s
call cursor(l, c)
endfunction
" fugitive
autocmd BufReadPost fugitive://* set bufhidden=delete " delete old fugitive buffers
" Tabularize mappings
let mapleader=','
if exists(":Tabularize")
nmap <Leader>a= :Tabularize /=<CR>
vmap <Leader>a= :Tabularize /=<CR>
nmap <Leader>a: :Tabularize /:\zs<CR>
vmap <Leader>a: :Tabularize /:\zs<CR>
endif
inoremap <silent> <Bar> <Bar><Esc>:call <SID>align()<CR>a
function! s:align()
let p = '^\s*|\s.*\s|\s*$'
if exists(':Tabularize') && getline('.') =~# '^\s*|' && (getline(line('.')-1) =~# p || getline(line('.')+1) =~# p)
let column = strlen(substitute(getline('.')[0:col('.')],'[^|]','','g'))
let position = strlen(matchstr(getline('.')[0:col('.')],'.*|\s*\zs.*'))
Tabularize/|/l1
normal! 0
call search(repeat('[^|]*|',column).'\s\{-\}'.repeat('.',position),'ce',line('.'))
endif
endfunction
" The custom :Qargs command sets the arglist to contain each of the files referenced by the quickfix list.
command! -nargs=0 -bar Qargs execute 'args' QuickfixFilenames()
function! QuickfixFilenames()
" Building a hash ensures we get each buffer only once
let buffer_numbers = {}
for quickfix_item in getqflist()
let buffer_numbers[quickfix_item['bufnr']] = bufname(quickfix_item['bufnr'])
endfor
return join(map(values(buffer_numbers), 'fnameescape(v:val)'))
endfunction
" Python settings
" -----------------------------
" Python-mode
" Activate rope
" Keys:
" K Show python docs
" <Ctrl-Space> Rope autocomplete
" <Ctrl-c>g Rope goto definition
" <Ctrl-c>d Rope show documentation
" <Ctrl-c>f Rope find occurrences
" <Leader>b Set, unset breakpoint (g:pymode_breakpoint enabled)
" [[ Jump on previous class or function (normal, visual, operator modes)
" ]] Jump on next class or function (normal, visual, operator modes)
" [M Jump on previous class or method (normal, visual, operator modes)
" ]M Jump on next class or method (normal, visual, operator modes)
let g:pymode_rope = 1
" Documentation
let g:pymode_doc = 1
let g:pymode_doc_key = 'K'
"Linting
let g:pymode_lint = 1
let g:pymode_lint_checker = "pyflakes,pep8"
" Auto check on save
let g:pymode_lint_write = 1
let g:pymode_lint_ignore="E703"
" Support virtualenv
let g:pymode_virtualenv = 1
" Enable breakpoints plugin
let g:pymode_breakpoint = 1
let g:pymode_breakpoint_key = '<leader>b'
" syntax highlighting
let g:pymode_syntax = 1
let g:pymode_syntax_all = 1
let g:pymode_syntax_indent_errors = g:pymode_syntax_all
let g:pymode_syntax_space_errors = g:pymode_syntax_all
" Don't autofold code
" let g:pymode_folding = 0
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" KEEP THIS AT END OF .vimrc
"
" Set directory-wise configuration.
" Search from the directory the file is located upwards to the root for
" a local configuration file called .lvimrc and sources it.
"
" The local configuration file is expected to have commands affecting
" only the current buffer.
function! SetLocalOptions(fname)
let dirname = fnamemodify(a:fname, ":p:h")
while "/" != dirname
let lvimrc = dirname . "/.lvimrc"
if filereadable(lvimrc)
execute "source " . lvimrc
break
endif
let dirname = fnamemodify(dirname, ":p:h:h")
endwhile
endfunction
au BufNewFile,BufRead * call SetLocalOptions(bufname("%"))
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""