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