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