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