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