Features by Gerhard
[shutils.git] / dotfiles / vim / .vimrc
1 " Purpose: My personal .vimrc
2 " Author: Stefan Huber
3
4 "profile start /tmp/profile.log
5 "profile func *
6 "profile file *
7
8 set encoding=utf8
9 set number
10 set backspace=indent,eol,start
11
12 set mouse=a
13
14 set tagstack
15 set grepprg=grep\ -nH\ $*
16 set foldcolumn=1
17
18 set incsearch
19 set hlsearch
20
21 set cursorline
22 set laststatus=2
23 set scrolloff=4
24
25 set listchars=tab:»­,trail:·,eol:$
26 set virtualedit=block
27
28 set autoindent
29 set tabstop=4
30 set shiftwidth=4
31 set expandtab
32
33 if version >= 703
34 set spelllang=de_at,en
35 set tabpagemax=20
36 set colorcolumn=+1
37 endif
38
39 set wildmode=longest,list:longest
40
41 set tags=./tags;/
42
43 syntax on
44 filetype plugin indent on
45
46 runtime! autoload/plug.vim
47 " Check if there is vim-plug installed
48 if exists('g:loaded_plug')
49 call plug#begin('~/.config/nvim/plugged')
50 Plug 'Glench/Vim-Jinja2-Syntax'
51 Plug 'LaTeX-Box-Team/LaTeX-Box'
52 Plug 'benekastah/neomake'
53 Plug 'vim-airline/vim-airline'
54 Plug 'vim-airline/vim-airline-themes'
55 Plug 'chrisbra/csv.vim'
56 Plug 'craigemery/vim-autotag'
57 Plug 'derekwyatt/vim-fswitch'
58 Plug 'godlygeek/tabular'
59 "Plug 'kien/ctrlp.vim'
60 Plug 'junegunn/fzf'
61 Plug 'majutsushi/tagbar'
62 Plug 'mhinz/vim-signify'
63 Plug 'msanders/snipmate.vim'
64 Plug 'scrooloose/nerdcommenter'
65 Plug 'scrooloose/nerdtree'
66 " Plug 'scrooloose/syntastic'
67 Plug 'sjl/splice.vim'
68 Plug 'Shougo/deoplete.nvim'
69 Plug 'suan/vim-instant-markdown'
70 Plug 'StanAngeloff/php.vim'
71 Plug 't4ku/marktag'
72 Plug 'thinca/vim-fontzoom'
73 Plug 'tpope/vim-ragtag'
74 Plug 'vim-scripts/CSApprox'
75 Plug 'vim-scripts/DetectIndent'
76 Plug 'vim-scripts/git_patch_tags.vim'
77 Plug 'vim-scripts/loremipsum'
78 call plug#end()
79
80 autocmd! BufWritePost,BufEnter * Neomake
81
82 " If there is no vim-plug, try pathogen
83 else
84 runtime autoload/pathogen.vim
85 if exists("g:loaded_pathogen")
86 " Pathogen runtime path manipulation
87 call pathogen#runtime_append_all_bundles()
88 call pathogen#helptags()
89 endif
90 endif
91
92
93 if has('nvim')
94 set rtp^=/usr/share/vim/vimfiles
95 else
96 set nocompatible
97 endif
98
99 " Color settings
100 if !has('nvim')
101 set t_Co=256
102 else
103 let $NVIM_TUI_ENABLE_TRUE_COLOR=1
104 endif
105 let g:CSApprox_attr_map = { 'bold' : 'bold', 'italic' : 'underline', 'sp' : 'bg' }
106
107 colorscheme shuber-wombat
108
109
110 " Use the below highlight group when displaying bad whitespace is desired.
111 highlight BadWhitespace ctermbg=red guibg=red
112 " Make trailing whitespace be flagged as bad.
113 au Filetype python,tex,c,cpp,cs,objc,java,vim syn match BadWhitespace /\s\+$/ containedin=ALL
114 au Filetype python,tex,c,cpp,cs,objc,java,vim let g:airline#extensions#whitespace#enabled = 0
115
116
117 " Detect indentation, but otherwise set expandtab
118 if exists(":DetectIndent")
119 au BufReadPost * :DetectIndent
120 endif
121
122
123 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
124 " Airline
125 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
126
127 let g:airline_powerline_fonts = 0
128 let g:airline_theme = 'wombat'
129
130 let g:airline#extensions#tabline#enabled = 1
131 let g:airline#extensions#tagbar#enabled = 0
132 let g:airline#extensions#whitespace#enabled = 0
133 let g:airline#extensions#branch#enabled = 1
134 let g:airline#extensions#branch#use_vcscommand = 1
135
136 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
137 " Some macros
138 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
139
140 "Open current file with a specific program
141 function OpenIn(prog)
142 execute ":!" . a:prog . " % &"
143 endfunction
144
145
146 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
147 " key bindings
148 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
149
150 nmap <s-PageDown> :bn<CR>
151 nmap <s-PageUp> :bp<CR>
152
153 map <a-c> <plug>NERDCommenterToggle
154 nmap <F10> :TagbarToggle<CR>
155
156 "nmap <c-q> :q<CR>
157 "nmap <c-s> :w<CR>
158 "vmap <c-s> <Esc><c-s>gv
159 "imap <c-s> <c-o><c-s>
160
161
162
163 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
164 " NERDTree
165 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
166 nmap <F9> :NERDTreeToggle<CR>
167 let g:NERDTreeDirArrows = 1
168 let g:NERDTreeDirArrowExpandable = '▸'
169 let g:NERDTreeDirArrowCollapsible = '▾'
170
171
172 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
173 " fortran
174 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
175
176 "let fortran_free_source=1
177 au BufNewFile *.f90 set fortran_free_source=1
178 au Filetype fortran set cindent cst csto=0
179
180
181 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
182 " C, C++, C#, objc, java
183 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
184
185 au Filetype c,cpp,cs,objc,java set cindent cst csto=0
186
187 au Filetype c,cpp,cs,objc,java map <buffer> <F4> :cnext<CR>
188 au Filetype c,cpp,cs,objc,java map <buffer> <S-F4> :cprevious<CR>
189
190 au Filetype c,cpp,cs,objc set makeprg=make
191 au Filetype c,cpp,cs,objc map <buffer> <F7> :make<CR>
192 au Filetype java map <buffer> <F7> :!ant -f ../build.xml<CR>
193
194 " If FSwitch exists
195 runtime! plugin/fswitch.vim
196 if exists(":FSHere")
197 au Filetype c,cpp,objc map <buffer> <F11> :vsplit<CR>:FSRight<CR>
198 au Filetype c,cpp,objc map <buffer> <S-F11> :FSHere<CR>
199
200 " Substitute lib <-> include, otherwise take the same directory
201 au BufEnter *.c* let b:fswitchlocs='reg:/lib/include/,rel:.'
202 au BufEnter *.h* let b:fswitchlocs='reg:/include/lib/,rel:.'
203 "au BufEnter *.c* let b:fswitchlocs='rel:.,rel:../inc*/**,rel:../../inc*/**'
204
205 au BufEnter *.cpp,*.cc,*.cxx let b:fswitchdst='h,hxx,hpp,hh'
206 au BufEnter *.h,*.hh,*.hxx let b:fswitchdst='cc,c,cxx,cpp'
207 else
208 au Filetype c,cpp,cs,objc,java map <buffer> <F11> :AS<CR>
209 au Filetype c,cpp,cs,objc,java map <buffer> <S-F11> :A<CR>
210 endif
211
212
213 "Prepend the namespace to an identifier, e.g. 'std::' before 'map' excluding
214 "those in C/C++ comments.
215 function PrependCppNamespaceToIdent(ns, id)
216
217 " To match Not to match
218 "
219 "|id |// id
220 "| id |// /* */ id
221 "|/* */ /* */ id |/* */ // id
222 "|id /* */ |/* id
223 "|*/ id | * id
224 " |/* id */
225 " |::id
226 " |/**/ ::id
227 " |#include <id>
228 "
229 " In order to not match '* id' it is assumed that multi-line comment lines
230 " in the middle begin with a star.
231
232 " If #include and // and /* and ^* and :: is not prepend:
233 execute ':%s@\(\(#include\|\/\/\|\/\*\|^\s*\*[^/]\).*\|::\)\@<!\<' . a:id . '\>@' . a:ns . '::' . a:id . '@ge'
234 " If #include and // and :: is not prepend, but */ is, and no further /* or // are found
235 execute ':%s@\(\(#include\|\/\/\).*\)\@<!\*\/\(\/[^\/\*]\|[^\/]\)*\zs\(::\)\@<!\<' . a:id . '\>@' . a:ns . '::' . a:id . '@ge'
236
237 endfunction
238
239 "Prepend STL namespace 'std::' to several identifiers
240 function PrependSTLNamespace()
241 " This list of identifier is not complete, but adding all of them is too
242 " much. We rather like to add identifieres that are 'typical' for C++.
243 " Others, like 'move' are likely to not be C++ specific. In this cases the
244 " user is asked to call PrependCppNamespaceToIdent by hand.
245 let id = []
246 let id = id +['cin', 'cout', 'cerr', 'endl']
247 let id = id +['swap', 'sort', 'max', 'min']
248 let id = id +['vector', 'deque', 'list', 'map', 'multimap', 'set']
249 let id = id +['queue', 'stack', 'priority_queue']
250 let id = id +['ostream', 'istream', 'sstream']
251 let id = id +['pair', 'string']
252
253 for i in id
254 call PrependCppNamespaceToIdent("std", i)
255 endfor
256 endfunction
257
258 function EscapeHexToChar()
259 echo 'Call "x/Nxb addr" in GDB to print N bytes at addr'
260 execute '%s/^.*://'
261 execute '%s/\s*0x\(\x\x\)/\\x\1/g'
262 execute '%s/^\(.*\)$/"\1"/'
263 endfunction
264
265 function InsertIncludeGuardsWithoutEndif()
266 let gatename = substitute(expand("%:t"), "\\.", "_", "g") . '_' . strpart(system('pwgen -c 16 1'), 0, 16)
267 execute "normal! i#ifndef " . gatename
268 execute "normal! o#define " . gatename
269 endfunction
270
271 function AddIncludeGuards()
272 execute "normal! Go#endif"
273 execute "normal! gg"
274 call InsertIncludeGuardsWithoutEndif()
275 endfunction
276
277 autocmd BufNewFile *.{h,hpp,hxx} call AddIncludeGuards()
278
279
280 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
281 " Text and mail
282 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
283
284 au Filetype text set textwidth=80
285 au Filetype markddown set textwidth=80
286 "According to thunderbirds settings
287 au Filetype mail set textwidth=72
288 au Filetype mail set expandtab
289
290 "a and w reformat the paragraph automatically and a new paragraph
291 "is indicated by lines not ending with white-space
292 if version>=700
293 au Filetype mail,text set fo+=n spell
294 endif
295
296 "Scissor line
297 au Filetype mail syn match Statement /^\s*-*\s*>8\s*-*\s*$/
298 au Filetype mail syn match Statement /^\s*-*\s*8<\s*-*\s*$/
299
300
301 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
302 " PHP
303 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
304
305 "au Filetype php set fo=tcqn
306 if version >= 700
307 au Filetype php set spell
308 endif
309
310 au Filetype php set textwidth=80
311 "au Filetype php set cindent
312
313
314 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
315 " maxima
316 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
317
318 au BufRead,BufNewFile *.wxm set filetype=maxima
319
320
321 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
322 " LaTeX
323 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
324
325 let g:LatexBox_split_side = "rightbelow"
326 "let g:LatexBox_split_resize = 1
327 let g:LatexBox_ref_pattern = '\c\\\a*ref\*\?\_\s*{'
328
329 let g:tex_flavor = "latex"
330 let g:LatexBox_output_type = "pdf"
331 let g:LatexBox_viewer = "okular"
332 let g:LatexBox_latexmk_async = 1
333 let g:LatexBox_latexmk_preview_continuously = 1
334 "let g:LatexBox_show_warnings = 0
335 let g:LatexBox_quickfix = 4
336
337 if version >= 700
338 au Filetype tex set spell
339 endif
340
341 au BufRead,BufNewFile *.cls set filetype=tex
342 au Filetype tex set textwidth=80
343 au Filetype tex set shiftwidth=2
344 au Filetype tex set smartindent
345 " Override Tagbar Toggle with LatexBox TOC
346 au Filetype tex nmap <buffer> <F10> :LatexTOCToggle<CR>
347 au Filetype tex nmap <buffer> <F11> :LatexLabels<CR>
348
349
350 "Remove Umlaute
351 function TexTransUmlaute()
352 execute ':%s/ü/\\\"u/ge'
353 execute ':%s/Ü/\\\"U/&'
354 execute ':%s/ö/\\\"o/&'
355 execute ':%s/Ö/\\\"O/&'
356 execute ':%s/ä/\\\"a/&'
357 execute ':%s/Ä/\\\"A/&'
358 execute ':%s/ß/\\\"s/&'
359 execute ':%s/²/\^2/&'
360 endfunction
361
362 function FindWordRepeatings()
363 execute '/\(\<\S\+\>\)\s\+\1\>'
364 " let pos = search('\(\<\S\+\>\)\s\+\1\>', "cw")
365 " call cursor(pos)
366 endfunction
367
368
369 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
370 " python
371 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
372
373 au Filetype python map <buffer> <F5> :!python % <CR>
374
375 " vimrc file for following the coding standards specified in PEP 7 & 8.
376
377 " Number of spaces that a pre-existing tab is equal to.
378 " For the amount of space used for a new tab use shiftwidth.
379 au Filetype python set shiftwidth=4
380 au Filetype python set expandtab
381
382 " Wrap text after a certain number of characters
383 au Filetype python set textwidth=79
384
385 let g:syntastic_python_checkers = ["pyflakes"]
386
387 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
388 " XML, Ipe
389 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
390
391 "Opens the current file in ipe
392 au BufRead,BufNewFile *.ipe set filetype=ipe
393 au Filetype xml,ipe map <buffer> <M-o> :call OpenIn("ipe") <CR>
394
395 au Filetype xml let g:tagbar_sort = 0
396 let g:tagbar_type_xml = {
397 \ 'ctagstype' : 'xml',
398 \ 'kinds' : [
399 \ 't:Tag'
400 \ ]
401 \ }
402
403 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
404 " gnuplot
405 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
406
407 "Opens the current file in ipe
408 au Filetype gnuplot map <buffer> <M-o> :call OpenIn("gnuplot -persist") <CR>
409
410
411 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
412 " remind
413 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
414
415 au BufRead,BufNewFile */.remind/* set filetype=remind
416
417
418 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
419 " vim-orgmode
420 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
421
422 au BufRead,BufNewFile *.org set filetype=org
423 let g:org_todo_keywords=['TODO', 'FEEDBACK', 'VERIFY', '|', 'DONE', 'DELEGATED']
424 let g:org_todo_keyword_faces = [['FEEDBACK', 'magenta'], ['TODO', 'yellow']]
425
426
427 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
428 " markdown
429 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
430
431 let g:instant_markdown_autostart = 0
432 let g:instant_markdown_slow = 1
433 au Filetype markdown map <buffer> <F5> :InstantMarkdownPreview<CR>
434 au Filetype markdown let g:tagbar_sort = 0
435
436 let g:tagbar_type_markdown = {
437 \ 'ctagstype' : 'markdown',
438 \ 'kinds' : [
439 \ 'h:Heading_L1',
440 \ 'i:Heading_L2',
441 \ 'k:Heading_L3'
442 \ ]
443 \ }
444
445 if executable('marktag')
446 let g:tagbar_type_markdown = {
447 \ 'ctagstype' : 'markdown',
448 \ 'ctagsbin' : 'marktag',
449 \ 'kinds' : [
450 \ 'h:header'
451 \ ],
452 \ 'sro' : '.',
453 \ 'kind2scope' : {
454 \ 'h' : 'header'
455 \ },
456 \ 'scope2kind' : {
457 \ 'header' : 'h'
458 \ }
459 \ }
460 end
461
462
463 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
464 " deoplete
465 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
466
467 if has('nvim')
468 let g:deoplete#enable_at_startup = 1
469 end
470
471 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
472 " youcompleteme
473 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
474
475 let g:ycm_global_ycm_extra_conf = '~/.ycm_extra_conf.py'
476 let g:ycm_confirm_extra_conf = 0
477
478 let g:ycm_min_num_of_chars_for_completion = 4
479 let g:ycm_collect_identifiers_from_tags_files = 1
480 let g:ycm_autoclose_preview_window_after_completion = 1
481
482 let g:ycm_key_list_select_completion = ['<Down>']
483 nnoremap <buffer> <leader>jd :YcmCompleter GoToDefinitionElseDeclaration<CR>
484
485 let g:ycm_filetype_whitelist = { 'c' : 1, 'cpp' : 1, 'cs' : 1, 'objc' : 1, 'java' : 1, 'python' : 1 }
486
487 "let g:ycm_server_use_vim_stdout = 1
488 "let g:ycm_server_log_level = 'debug'
489
490
491 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
492 " syntastic
493 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
494
495 let g:syntastic_mode_map = { 'mode' : 'active', 'active_filetypes' : [], 'passive_filetypes' : ['html'] }
496 let g:ycm_show_diagnostics_ui = 0
497 let g:syntastic_c_checkers = ["cppcheck"]
498 let g:syntastic_cpp_checkers = g:syntastic_c_checkers
499
500
501 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
502 " signify
503 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
504
505 let g:signify_vcs_list = ['git']
506
507
508
509
510 if filereadable($HOME . "/.vimrc-local")
511 source ~/.vimrc-local
512 endif
513
514 " Being able to load project specific vimrc files
515 set exrc
516 set secure
517
518