update vimrc
[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
13 " Pathogen runtime path manipulation
14 "call pathogen#infect() "Using the infect method breaks ft detection
15 filetype off
16 call pathogen#runtime_append_all_bundles()
17 call pathogen#helptags()
18
19 set encoding=utf8
20
21 "Activate syntax highlighting
22 syntax on
23 "Activate filetype plugins: syntax highlighting, indentation, and more
24 filetype plugin indent on
25
26 set modeline
27 set number
28 set backspace=indent,eol,start
29
30 "vim-7 and newer has vimspell (spell checker) built in
31 if version >= 703
32 set spelllang=de_at,en
33 set tabpagemax=20
34 "set colorcolumn=80,+1
35 set colorcolumn=+1
36 endif
37
38 "Set some properties for ctags, grep and the size of the
39 "most-left column for foldings
40 set tagstack
41 set grepprg=grep\ -nH\ $*
42 set foldcolumn=1
43
44 "Set incremental search and highlighted search results
45 set incsearch
46 set hlsearch
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
55 "Open current file with a specific program
56 function OpenIn(prog)
57 execute ":!" . a:prog . " % &"
58 endfunction
59
60
61 " Use the below highlight group when displaying bad whitespace is desired.
62 highlight BadWhitespace ctermbg=red guibg=red
63 " Make trailing whitespace be flagged as bad.
64 au Filetype python,tex,c,cpp,cs,objc,java syn match BadWhitespace /\s\+$/ containedin=ALL
65
66 set listchars=tab:»­,trail:·,eol:$
67
68
69 set autoindent
70 set tabstop=4
71 set shiftwidth=4
72 if exists(":DetectIndent")
73 au BufReadPost * :DetectIndent
74 endif
75 "au Filetype python,tex,c,cpp,cs,objc,java :DetectIndent
76 "let g:detectindent_preferred_expandtab = 1
77 "let g:detectindent_preferred_indent = 4
78
79
80
81 " Use 256 colors
82 set t_Co=256
83 let g:CSApprox_attr_map = { 'bold' : 'bold', 'italic' : '', 'sp' : '' }
84 colorscheme shuber-wombat
85
86 set cursorline
87 set laststatus=2
88
89
90 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
91 " key bindings
92 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
93
94 map <A-c> <plug>NERDCommenterToggle
95
96
97 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
98 " fortran
99 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
100
101 "let fortran_free_source=1
102 au BufNewFile *.f90 set fortran_free_source=1
103 au Filetype fortran set cindent cst csto=0
104
105
106 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
107 " C, C++, C#, objc, java
108 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
109
110 au Filetype c,cpp,cs,objc,java map <F4> :cnext <CR>
111 au Filetype c,cpp,cs,objc,java map <S-F4> :cprevious <CR>
112 au Filetype c,cpp,cs,objc,java map <F11> :AS <CR>
113 au Filetype c,cpp,cs,objc,java map <S-F11> :A <CR>
114 au Filetype c,cpp,cs,objc,java set cindent cst csto=0
115 au Filetype c,cpp,cs,objc map <F7> :make <CR>
116 au Filetype java map <F7> :!ant -f ../build.xml <CR>
117 au Filetype c,cpp,cs,obj set makeprg=make
118
119
120 "Adds STL prefix 'std::' to 'id'
121 function AddNamespaceDeclTo(ns, id)
122 echo "Add '" . a:ns . "' to " . a:id
123 "Line starts with a:id
124 execute ":%s!^\\(\\s*\\)" . a:id . "\\>!\\1" . a:ns . "::" . a:id . "!e"
125 "Line beginning, white space, not # or / (preprocessor or comment)
126 execute ":%s!^\\(\\s*[^#/].*[^:]\\)\\<" . a:id . "\\>!\\1" . a:ns . "::" . a:id . "!ge"
127 endfunction
128
129
130 "Adds STL prefix 'std::' to several identifiers
131 function AddSTLNamespaceDecl()
132 call AddNamespaceDeclTo("std","cin")
133 call AddNamespaceDeclTo("std","cout")
134 call AddNamespaceDeclTo("std","cerr")
135
136 call AddNamespaceDeclTo("std","swap")
137 call AddNamespaceDeclTo("std","sort")
138 call AddNamespaceDeclTo("std","max")
139 call AddNamespaceDeclTo("std","min")
140
141 call AddNamespaceDeclTo("std","deque")
142 call AddNamespaceDeclTo("std","endl")
143 call AddNamespaceDeclTo("std","list")
144 call AddNamespaceDeclTo("std","map")
145 call AddNamespaceDeclTo("std","multimap")
146 call AddNamespaceDeclTo("std","ostream")
147 call AddNamespaceDeclTo("std","pair")
148 call AddNamespaceDeclTo("std","priority_queue")
149 call AddNamespaceDeclTo("std","set")
150 call AddNamespaceDeclTo("std","queue")
151 call AddNamespaceDeclTo("std","stack")
152 call AddNamespaceDeclTo("std","string")
153 call AddNamespaceDeclTo("std","vector")
154 endfunction
155
156
157 function EscapeHexToChar()
158 echo 'Call "x/Nxb addr" in GDB to print N bytes at addr'
159 execute '%s/^.*://'
160 execute '%s/\s*0x\(\x\x\)/\\x\1/g'
161 execute '%s/^\(.*\)$/"\1"/'
162 endfunction
163
164
165
166 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
167 " Text and mail
168 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
169
170 au Filetype text set textwidth=80
171 "According to thunderbirds settings
172 au Filetype mail set textwidth=72
173
174 "a and w reformat the paragraph automatically and a new paragraph
175 "is indicated by lines not ending with white-space
176 if version>=700
177 au Filetype mail,text set fo+=n spell
178 endif
179
180 "Scissor line
181 au Filetype mail syn match Statement /^\s*-*\s*>8\s*-*\s*$/
182 au Filetype mail syn match Statement /^\s*-*\s*8<\s*-*\s*$/
183
184
185
186 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
187 " PHP
188 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
189
190 "au Filetype php set fo=tcqn
191 if version >= 700
192 au Filetype php set spell
193 endif
194
195 au Filetype php set textwidth=80
196 "au Filetype php set cindent
197
198
199
200
201 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
202 " LaTeX
203 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
204
205 au BufRead,BufNewFile *.cls set filetype=tex
206 au Filetype tex set textwidth=80
207
208 "Remove Umlaute
209 function TexTransUmlaute()
210 execute ':%s/ü/\\\"u/ge'
211 execute ':%s/Ü/\\\"U/&'
212 execute ':%s/ö/\\\"o/&'
213 execute ':%s/Ö/\\\"O/&'
214 execute ':%s/ä/\\\"a/&'
215 execute ':%s/Ä/\\\"A/&'
216 execute ':%s/ß/\\\"s/&'
217 execute ':%s/²/\^2/&'
218 endfunction
219
220
221 function FindWordRepeatings()
222 execute '/\(\<\S\+\>\)\s\+\1\>'
223 " let pos = search('\(\<\S\+\>\)\s\+\1\>', "cw")
224 " call cursor(pos)
225 endfunction
226
227
228 let g:tex_flavor = "latex"
229 let g:LatexBox_viewer="okular"
230 let g:LatexBox_latexmk_options="-pvc"
231
232 au Filetype tex set smartindent
233
234 au Filetype tex map! ,b \begin{}<Esc>i
235 au Filetype tex map! ,e <esc>:call TexClosePrev(0)<cr>a<cr>
236 au Filetype tex map! ,i \begin{itemize}<Return>\end{itemize}<ESC>O\item
237 au Filetype tex map! ,f \begin{frame}<Return>\end{frame}<ESC>O\frametitle{
238 au Filetype tex map! ,p \begin{figure}<Return>\end{figure}<ESC>O\centering<Return>\includegraphics{
239
240
241
242 if version >= 700
243 au Filetype tex set spell
244 endif
245
246
247
248 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
249 " python
250 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
251
252 au Filetype python map <F5> :!python % <CR>
253
254
255 " vimrc file for following the coding standards specified in PEP 7 & 8.
256
257 " Number of spaces that a pre-existing tab is equal to.
258 " For the amount of space used for a new tab use shiftwidth.
259 au Filetype python set shiftwidth=4
260 au Filetype python set expandtab
261
262 " Wrap text after a certain number of characters
263 au Filetype python set textwidth=79
264
265
266 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
267 " XML, Ipe
268 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
269
270 "Opens the current file in ipe
271 au Filetype xml map <M-o> :call OpenIn("ipe") <CR>
272
273
274 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
275 " gnuplot
276 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
277
278 "Opens the current file in ipe
279 au Filetype gnuplot map <M-o> :call OpenIn("gnuplot -persist") <CR>
280
281
282 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
283 " youcompleteme
284 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
285
286 let g:ycm_min_num_of_chars_for_completion = 999
287
288
289
290
291 if filereadable($HOME . "/.vimrc-local")
292 source ~/.vimrc-local
293 endif
294
295