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