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