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