]> git.sthu.org Git - shutils.git/blob - dotfiles/vim/.vimrc
vim: Update config files and scripts
[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 " Pathogen runtime path manipulation
43 "call pathogen#infect() "Using the infect method breaks ft detection
44 filetype off
45 call pathogen#runtime_append_all_bundles()
46 call pathogen#helptags()
47
48 syntax on
49 filetype plugin indent on
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' : '', 'sp' : '' }
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 = 0
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 map <a-c> <plug>NERDCommenterToggle
107 nmap <F9> :NERDTreeToggle<CR>
108 nmap <F10> :TagbarToggle<CR>
109
110 nmap <c-q> :q<CR>
111 nmap <c-s> :w<CR>
112 vmap <c-s> <Esc><c-s>gv
113 imap <c-s> <c-o><c-s>
114
115
116 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
117 " fortran
118 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
119
120 "let fortran_free_source=1
121 au BufNewFile *.f90 set fortran_free_source=1
122 au Filetype fortran set cindent cst csto=0
123
124
125 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
126 " C, C++, C#, objc, java
127 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
128
129 au Filetype c,cpp,cs,objc,java map <F4> :cnext <CR>
130 au Filetype c,cpp,cs,objc,java map <S-F4> :cprevious <CR>
131 au Filetype c,cpp,cs,objc,java map <F11> :AS <CR>
132 au Filetype c,cpp,cs,objc,java map <S-F11> :A <CR>
133 au Filetype c,cpp,cs,objc,java set cindent cst csto=0
134 au Filetype c,cpp,cs,objc map <F7> :make <CR>
135 au Filetype java map <F7> :!ant -f ../build.xml <CR>
136 au Filetype c,cpp,cs,obj set makeprg=make
137
138
139 "Prepend the namespace to an identifier, e.g. 'std::' before 'map' excluding
140 "those in C/C++ comments.
141 function PrependCppNamespaceToIdent(ns, id)
142
143 " To match Not to match
144 "
145 "|id |// id
146 "| id |// /* */ id
147 "|/* */ /* */ id |/* */ // id
148 "|id /* */ |/* id
149 "|*/ id | * id
150 " |/* id */
151 " |::id
152 " |/**/ ::id
153 " |#include <id>
154 "
155 " In order to not match '* id' it is assumed that multi-line comment lines
156 " in the middle begin with a star.
157
158 " If #include and // and /* and ^* and :: is not prepend:
159 execute ':%s@\(\(#include\|\/\/\|\/\*\|^\s*\*[^/]\).*\|::\)\@<!\<' . a:id . '\>@' . a:ns . '::' . a:id . '@ge'
160 " If #include and // and :: is not prepend, but */ is, and no further /* or // are found
161 execute ':%s@\(\(#include\|\/\/\).*\)\@<!\*\/\(\/[^\/\*]\|[^\/]\)*\zs\(::\)\@<!\<' . a:id . '\>@' . a:ns . '::' . a:id . '@ge'
162
163 endfunction
164
165 "Prepend STL namespace 'std::' to several identifiers
166 function PrependSTLNamespace()
167 " This list of identifier is not complete, but adding all of them is too
168 " much. We rather like to add identifieres that are 'typical' for C++.
169 " Others, like 'move' are likely to not be C++ specific. In this cases the
170 " user is asked to call PrependCppNamespaceToIdent by hand.
171 let id = []
172 let id = id +['cin', 'cout', 'cerr', 'endl']
173 let id = id +['swap', 'sort', 'max', 'min']
174 let id = id +['vector', 'deque', 'list', 'map', 'multimap', 'set']
175 let id = id +['queue', 'stack', 'priority_queue']
176 let id = id +['ostream', 'istream', 'sstream']
177 let id = id +['pair', 'string']
178
179 for i in id
180 call PrependCppNamespaceToIdent("std", i)
181 endfor
182 endfunction
183
184 function EscapeHexToChar()
185 echo 'Call "x/Nxb addr" in GDB to print N bytes at addr'
186 execute '%s/^.*://'
187 execute '%s/\s*0x\(\x\x\)/\\x\1/g'
188 execute '%s/^\(.*\)$/"\1"/'
189 endfunction
190
191 function InsertIncludeGuardsWithoutEndif()
192 let gatename = substitute(expand("%:t"), "\\.", "_", "g") . '_' . strpart(system('pwgen -c 16 1'), 0, 16)
193 execute "normal! i#ifndef " . gatename
194 execute "normal! o#define " . gatename
195 endfunction
196
197 function AddIncludeGuards()
198 execute "normal! Go#endif"
199 execute "normal! gg"
200 call InsertIncludeGuardsWithoutEndif()
201 endfunction
202
203 autocmd BufNewFile *.{h,hpp,hxx} call AddIncludeGuards()
204
205
206 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
207 " Text and mail
208 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
209
210 au Filetype text set textwidth=80
211 "According to thunderbirds settings
212 au Filetype mail set textwidth=72
213 au Filetype mail set expandtab
214
215 "a and w reformat the paragraph automatically and a new paragraph
216 "is indicated by lines not ending with white-space
217 if version>=700
218 au Filetype mail,text set fo+=n spell
219 endif
220
221 "Scissor line
222 au Filetype mail syn match Statement /^\s*-*\s*>8\s*-*\s*$/
223 au Filetype mail syn match Statement /^\s*-*\s*8<\s*-*\s*$/
224
225
226 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
227 " PHP
228 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
229
230 "au Filetype php set fo=tcqn
231 if version >= 700
232 au Filetype php set spell
233 endif
234
235 au Filetype php set textwidth=80
236 "au Filetype php set cindent
237
238
239 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
240 " maxima
241 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
242
243 au BufRead,BufNewFile *.wxm set filetype=maxima
244
245
246 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
247 " LaTeX
248 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
249
250 au BufRead,BufNewFile *.cls set filetype=tex
251 au Filetype tex set textwidth=80
252
253 "Remove Umlaute
254 function TexTransUmlaute()
255 execute ':%s/ü/\\\"u/ge'
256 execute ':%s/Ü/\\\"U/&'
257 execute ':%s/ö/\\\"o/&'
258 execute ':%s/Ö/\\\"O/&'
259 execute ':%s/ä/\\\"a/&'
260 execute ':%s/Ä/\\\"A/&'
261 execute ':%s/ß/\\\"s/&'
262 execute ':%s/²/\^2/&'
263 endfunction
264
265 function FindWordRepeatings()
266 execute '/\(\<\S\+\>\)\s\+\1\>'
267 " let pos = search('\(\<\S\+\>\)\s\+\1\>', "cw")
268 " call cursor(pos)
269 endfunction
270
271 let g:tex_flavor = "latex"
272 let g:LatexBox_output_type = "pdf"
273 let g:LatexBox_viewer = "okular"
274 let g:LatexBox_latexmk_async = 1
275 let g:LatexBox_latexmk_preview_continuously = 1
276 let g:LatexBox_show_warnings = 0
277 let g:LatexBox_quickfix = 2
278
279 au Filetype tex set smartindent
280
281 if version >= 700
282 au Filetype tex set spell
283 endif
284
285
286 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
287 " python
288 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
289
290 au Filetype python map <F5> :!python % <CR>
291
292 " vimrc file for following the coding standards specified in PEP 7 & 8.
293
294 " Number of spaces that a pre-existing tab is equal to.
295 " For the amount of space used for a new tab use shiftwidth.
296 au Filetype python set shiftwidth=4
297 au Filetype python set expandtab
298
299 " Wrap text after a certain number of characters
300 au Filetype python set textwidth=79
301
302
303 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
304 " XML, Ipe
305 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
306
307 "Opens the current file in ipe
308 au Filetype xml map <M-o> :call OpenIn("ipe") <CR>
309
310
311 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
312 " gnuplot
313 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
314
315 "Opens the current file in ipe
316 au Filetype gnuplot map <M-o> :call OpenIn("gnuplot -persist") <CR>
317
318
319 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
320 " remind
321 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
322
323 au BufRead,BufNewFile */.remind/* set filetype=remind
324
325
326 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
327 " youcompleteme
328 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
329
330 "let g:ycm_path_to_python_interpreter = '/usr/bin/python'
331 let g:ycm_global_ycm_extra_conf = '/home/shuber/.ycm_extra_conf.py'
332 let g:ycm_min_num_of_chars_for_completion = 999
333 let g:ycm_key_list_select_completion = ['<Down>']
334 let g:ycm_collect_identifiers_from_tags_files = 1
335 let g:ycm_autoclose_preview_window_after_completion = 1
336 nnoremap <leader>jd :YcmCompleter GoToDefinitionElseDeclaration<CR>
337
338 "let g:ycm_server_use_vim_stdout = 1
339 "let g:ycm_server_log_level = 'debug'
340
341
342 if filereadable($HOME . "/.vimrc-local")
343 source ~/.vimrc-local
344 endif
345
346 " Being able to load project specific vimrc files
347 set exrc
348 set secure
349
350