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