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