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