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