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