8c716d410c85344ece65201c3fee7c818bb2d6e4
[shutils.git] / dotfiles / vim / .vimrc
1 " Purpose: My personal .vimrc
2 " Author: Stefan Huber
3 "
4 "Essential resources for vim users
5 " - vim.sf.net -- find tips and scripts for vim and gvim
6 "
7 "By calling ":help keyword" you get help for the specific
8 "option and setting.
9
10
11 set nocompatible
12 set encoding=utf8
13 set modeline
14 set number
15 set backspace=indent,eol,start
16
17 set tagstack
18 set grepprg=grep\ -nH\ $*
19 set foldcolumn=1
20
21 set incsearch
22 set hlsearch
23
24 set cursorline
25 set laststatus=2
26
27 set listchars=tab:»­,trail:·,eol:$
28
29 set autoindent
30 set tabstop=4
31 set shiftwidth=4
32
33 if version >= 703
34 set spelllang=de_at,en
35 set tabpagemax=20
36 set colorcolumn=+1
37 endif
38
39 " Pathogen runtime path manipulation
40 "call pathogen#infect() "Using the infect method breaks ft detection
41 filetype off
42 call pathogen#runtime_append_all_bundles()
43 call pathogen#helptags()
44
45 syntax on
46 filetype plugin indent on
47
48
49 "Power saving tip: powertop-homepage
50 let &guicursor = &guicursor . ",a:blinkon0"
51 "According to vim help -- enable mouse in xterm...
52 set mouse=a
53
54 " Use 256 colors
55 set t_Co=256
56 let g:CSApprox_attr_map = { 'bold' : 'bold', 'italic' : '', 'sp' : '' }
57 colorscheme shuber-wombat
58
59
60 " Use the below highlight group when displaying bad whitespace is desired.
61 highlight BadWhitespace ctermbg=red guibg=red
62 " Make trailing whitespace be flagged as bad.
63 au Filetype python,tex,c,cpp,cs,objc,java,vim syn match BadWhitespace /\s\+$/ containedin=ALL
64
65
66 if exists(":DetectIndent")
67 au BufReadPost * :DetectIndent
68 endif
69
70
71 let g:syntastic_mode_map = { 'mode' : 'active', 'active_filetypes' : [], 'passive_filetypes' : ['html'] }
72
73
74 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
75 " Some macros
76 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
77
78 "Open current file with a specific program
79 function OpenIn(prog)
80 execute ":!" . a:prog . " % &"
81 endfunction
82
83
84 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
85 " key bindings
86 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
87
88 map <a-c> <plug>NERDCommenterToggle
89
90 nmap <c-q> :q<CR>
91 nmap <c-s> :w<CR>
92 vmap <c-s> <Esc><c-s>gv
93 imap <c-s> <c-o><c-s>
94
95
96 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
97 " fortran
98 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
99
100 "let fortran_free_source=1
101 au BufNewFile *.f90 set fortran_free_source=1
102 au Filetype fortran set cindent cst csto=0
103
104
105 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
106 " C, C++, C#, objc, java
107 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
108
109 au Filetype c,cpp,cs,objc,java map <F4> :cnext <CR>
110 au Filetype c,cpp,cs,objc,java map <S-F4> :cprevious <CR>
111 au Filetype c,cpp,cs,objc,java map <F11> :AS <CR>
112 au Filetype c,cpp,cs,objc,java map <S-F11> :A <CR>
113 au Filetype c,cpp,cs,objc,java set cindent cst csto=0
114 au Filetype c,cpp,cs,objc map <F7> :make <CR>
115 au Filetype java map <F7> :!ant -f ../build.xml <CR>
116 au Filetype c,cpp,cs,obj set makeprg=make
117
118
119 "Prepend the namespace to an identifier, e.g. 'std::' before 'map' excluding
120 "those in C/C++ comments.
121 function PrependCppNamespaceToIdent(ns, id)
122
123 " To match Not to match
124 "
125 "|id |// id
126 "| id |// /* */ id
127 "|/* */ /* */ id |/* */ // id
128 "|id /* */ |/* id
129 "|*/ id | * id
130 " |/* id */
131 " |::id
132 " |/**/ ::id
133 " |#include <id>
134 "
135 " In order to not match '* id' it is assumed that multi-line comment lines
136 " in the middle begin with a star.
137
138 " If #include and // and /* and ^* and :: is not prepend:
139 execute ':%s_\(\(#include\|\/\/\|\/\*\|^\s*\*[^/]\).*\|::\)\@<!\<' . a:id . '\>_' . a:ns . '::' . a:id . '_ge'
140 " If #include and // and :: is not prepend, but */ is, and no further /* or // are found
141 execute ':%s_\(\(#include\|\/\/\).*\)\@<!\*\/\(\/[^\/\*]\|[^\/]\)*\zs\(::\)\@<!\<' . a:id . '\>_' . a:ns . '::' . a:id . '_ge'
142
143 endfunction
144
145 "Prepend STL namespace 'std::' to several identifiers
146 function PrependSTLNamespace()
147 " This list of identifier is not complete, but adding all of them is too
148 " much. We rather like to add identifieres that are 'typical' for C++.
149 " Others, like 'move' are likely to not be C++ specific. In this cases the
150 " user is asked to call PrependCppNamespaceToIdent by hand.
151 let id = []
152 let id = id +['cin', 'cout', 'cerr', 'endl']
153 let id = id +['swap', 'sort', 'max', 'min']
154 let id = id +['vector', 'deque', 'list', 'map', 'multimap', 'set']
155 let id = id +['queue', 'stack', 'priority_queue']
156 let id = id +['ostream', 'istream', 'sstream']
157 let id = id +['pair', 'string']
158 let id = ['map']
159
160 for i in id
161 call PrependCppNamespaceToIdent("std", i)
162 endfor
163 endfunction
164
165 function EscapeHexToChar()
166 echo 'Call "x/Nxb addr" in GDB to print N bytes at addr'
167 execute '%s/^.*://'
168 execute '%s/\s*0x\(\x\x\)/\\x\1/g'
169 execute '%s/^\(.*\)$/"\1"/'
170 endfunction
171
172
173
174 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
175 " Text and mail
176 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
177
178 au Filetype text set textwidth=80
179 "According to thunderbirds settings
180 au Filetype mail set textwidth=72
181 au Filetype mail set expandtab
182
183 "a and w reformat the paragraph automatically and a new paragraph
184 "is indicated by lines not ending with white-space
185 if version>=700
186 au Filetype mail,text set fo+=n spell
187 endif
188
189 "Scissor line
190 au Filetype mail syn match Statement /^\s*-*\s*>8\s*-*\s*$/
191 au Filetype mail syn match Statement /^\s*-*\s*8<\s*-*\s*$/
192
193
194 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
195 " PHP
196 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
197
198 "au Filetype php set fo=tcqn
199 if version >= 700
200 au Filetype php set spell
201 endif
202
203 au Filetype php set textwidth=80
204 "au Filetype php set cindent
205
206
207 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
208 " LaTeX
209 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
210
211 au BufRead,BufNewFile *.cls set filetype=tex
212 au Filetype tex set textwidth=80
213
214 "Remove Umlaute
215 function TexTransUmlaute()
216 execute ':%s/ü/\\\"u/ge'
217 execute ':%s/Ü/\\\"U/&'
218 execute ':%s/ö/\\\"o/&'
219 execute ':%s/Ö/\\\"O/&'
220 execute ':%s/ä/\\\"a/&'
221 execute ':%s/Ä/\\\"A/&'
222 execute ':%s/ß/\\\"s/&'
223 execute ':%s/²/\^2/&'
224 endfunction
225
226 function FindWordRepeatings()
227 execute '/\(\<\S\+\>\)\s\+\1\>'
228 " let pos = search('\(\<\S\+\>\)\s\+\1\>', "cw")
229 " call cursor(pos)
230 endfunction
231
232 let g:tex_flavor = "latex"
233 let g:LatexBox_viewer="okular"
234 let g:LatexBox_latexmk_options="-pvc"
235
236 au Filetype tex set smartindent
237
238 if version >= 700
239 au Filetype tex set spell
240 endif
241
242
243 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
244 " python
245 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
246
247 au Filetype python map <F5> :!python % <CR>
248
249 " vimrc file for following the coding standards specified in PEP 7 & 8.
250
251 " Number of spaces that a pre-existing tab is equal to.
252 " For the amount of space used for a new tab use shiftwidth.
253 au Filetype python set shiftwidth=4
254 au Filetype python set expandtab
255
256 " Wrap text after a certain number of characters
257 au Filetype python set textwidth=79
258
259
260 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
261 " XML, Ipe
262 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
263
264 "Opens the current file in ipe
265 au Filetype xml map <M-o> :call OpenIn("ipe") <CR>
266
267
268 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
269 " gnuplot
270 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
271
272 "Opens the current file in ipe
273 au Filetype gnuplot map <M-o> :call OpenIn("gnuplot -persist") <CR>
274
275
276 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
277 " youcompleteme
278 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
279
280 let g:ycm_min_num_of_chars_for_completion = 999
281 let g:ycm_key_list_select_completion = ['<Down>']
282
283
284
285 if filereadable($HOME . "/.vimrc-local")
286 source ~/.vimrc-local
287 endif
288
289