1 " from http://bwaldvogel.de/rc/vim.html
  2 " the XHTML files are generated using :%TOhtml
  3 "
  4 " also an excellent vimrc:
  5 "   http://www.jukie.net/~bart/conf/vimrc
  6 "
  7 " nice blog post:
  8 "   http://items.sjbach.com/319/configuring-vim-right
  9 "
 10 " startup benchmarks
 11 "
 12 " • vim-7.1.028
 13 "   # time vim -cq
 14 "     vim -cq  0.25s user 0.02s system 88% cpu 0.302 total
 15 " • vim-7.1.042
 16 "   # time vim -cq
 17 "     vim -cq  0.09s user 0.01s system 95% cpu 0.101 total
 18 "
 19 " use :help <keyword> in case you don't know what something stands for
 20 
 21 """ tricks
 22 " 1. enumerate lines in block mode
 23 "   C-v !cat -n
 24 "   or better use VisIncr → c-V :I [#]
 25 "
 26 " 2. insert unicode characters
 27 "   <C-v>u20ac → €
 28 
 29 set nocompatible
 30 set showcmd
 31 
 32 " be careful: tabs may look different on other systems
 33 set tabstop=4
 34 set shiftwidth=4
 35 set autoindent
 36 set smartindent
 37 
 38 " don't go to the start of line when doing G etc.
 39 set nosol
 40 
 41 " recognize lines as you can see at the bottom
 42 set modeline
 43 set modelines=3
 44 
 45 " don't insert TWO spaces after '.', '?' etc. when joining lines
 46 set nojoinspaces
 47 
 48 " do macros, do them FAST!
 49 set lazyredraw
 50 
 51 " pop a completion list when pressing <tab> (like zsh does...)
 52 set wildmenu
 53 " have the completion similar to shell completion
 54 set wildmode=list:longest
 55 set wildignore=*.class,*.o,*.bak,*.swp,*.tmp,*.part
 56 
 57 " display also the hexcode of the char under the cursor
 58 set rulerformat=0x%02B\ %3p%%\ %l,%c%V
 59 " allways show the ruler
 60 set ruler
 61 
 62 " don't give the intro message when starting
 63 set shortmess+=I
 64 
 65 let maplocalleader=','
 66 
 67 " no, I don't like that - it's too much
 68 " set laststatus=2
 69 " set statusline=%<%F%=\ [%1*%M%*%n%R%H%Y]\ \ %-25(%3l,%c%03V\ \ %P\ (%L)%)%12o'%03b''%03B'
 70 
 71 " allow backspacing over autoindent, line breaks (join lines),
 72 " the start of insert; CTRL-W and CTRL-U stop once at the start of insert.
 73 set backspace=indent,eol,start
 74 
 75 " debugging {{{1
 76 " set verbosefile=/tmp/vim.verbose
 77 " set verbose=100
 78 
 79 " {{{1 highlighting
 80 " see ~/.vim/after/syntax/syncolor.vim too
 81 syntax on
 82 " color scheme for dark backgrounds >:)
 83 set background=dark
 84 " :so $VIMRUNTIME/syntax/hitest.vim
 85 
 86 " I configure my screen with --enable-colors256 (Gentoo does this by default!)
 87 if $TERM =~ '^screen' | set t_Co=256 | endif
 88 " I use a patched rxvt-unicode which is able to display 256 colors
 89 if $TERM =~ '^rxvt-unicode' | set t_Co=256 | endif
 90 if $TERM =~ '^xterm' | set t_Co=256 | endif
 91 
 92 if &t_Co >= 256
 93   try
 94     colorscheme 256asu1black
 95   catch
 96     colorscheme pablo
 97   endtry
 98 else
 99   colorscheme pablo
100 endif
101 
102 " favourite colorschemes:
103 "  • 256_asu1dark
104 "  • pablo
105 "  • torte
106 "  • desert256
107 
108 hi StatusLine ctermfg=black ctermbg=white
109 
110 " {{{1 Python
111 " I want all possible Python highlighting (see ft-python-syntax)
112 let python_highlight_all=1
113 au FileType python source ~/.vim/scripts/python.vim
114 
115 " {{{1 folding (see :h folding)
116 " show all folds closed
117 set foldenable
118 " fold on markers tripple {
119 set foldmethod=marker
120 autocmd FileType c,cpp,d,perl,java,cs set foldmethod=syntax
121 autocmd FileType python set foldmethod=indent
122 set foldcolumn=1
123 set foldlevel=99
124 
125 "Comments {{{1
126 vmap <silent> <LocalLeader>c <Plug>VisualTraditional
127 nmap <silent> <LocalLeader>c <Plug>Traditional
128 " don't create mapping for the insert mode
129 let g:EnhCommentifyBindInInsert = 'No'
130 let g:EnhCommentifyMultiPartBlocks = 'Yes'
131 let g:EnhCommentifyPretty = 'Yes'
132 let g:EnhCommentifyRespectIndent = 'Yes'
133 let g:EnhCommentifyUseBlockIndent = 'Yes'
134 " New filetypes (callback since EC v2.3)
135 function EnhCommentifyCallback(ft)
136   if a:ft =~ '\v(gentoo-package-(keywords|use|(un)?mask)|cmake)'
137     let b:ECcommentOpen = '#'
138     let b:ECcommentClose = ''
139   endif
140 endfunction
141 let g:EnhCommentifyCallbackExists = 'Yes'
142 " searching {{{1
143 " highlight search
144 set hls
145 " higlight while searching
146 set incsearch
147 " search for upper and lowercase
148 set ignorecase
149 " but if user types uppercase - search exactly
150 set smartcase
151 nmap <silent> <LocalLeader>n :nohlsearch<cr>
152 
153 " Files (types, skeletons, indenting) {{{1
154 " detect filetypes and turn on indentation (cindent for c files e.g.)
155 filetype plugin indent on
156 " break c/c++/perl/python/java after 80 lines
157 " comments only, but it depends on 'formatoptions'
158 
159 " Indenting in source files
160 autocmd FileType c,cpp,cs,d,html,java,perl,php,python,shell,vim,xhtml,xml,xslt,xsl set tabstop=2 shiftwidth=2 noexpandtab
161 " automatic detection of et,sw,ts setting with script #1171
162 autocmd BufReadPost * :DetectIndent
163 
164 " skeletons {{{2
165 " perl
166 autocmd BufNewFile *.pl 0r ~/.vim/skeleton.pl|normal G
167 " python
168 autocmd BufNewFile *.py 0r ~/.vim/skeleton.py|normal G
169 " C
170 autocmd BufNewFile *.c 0r ~/.vim/skeleton.c|normal G
171 " C++
172 autocmd BufNewFile *.cpp 0r ~/.vim/skeleton.cpp|normal G
173 " D
174 autocmd BufNewFile *.d 0r ~/.vim/skeleton.d|normal G
175 " (X)HTML
176 autocmd BufNewFile *.html 0r ~/.vim/skeleton.html|normal GddA
177 autocmd BufNewFile *.xhtml,*.shtml 0r ~/.vim/skeleton.xhtml|set ft=xhtml|normal G
178 " XML
179 autocmd BufNewFile *.xml 0r ~/.vim/skeleton.xml|normal G
180 " XSL
181 autocmd BufNewFile *.xsl 0r ~/.vim/skeleton.xsl|normal 2j26|
182 " Shell
183 autocmd BufNewFile *.sh 0r ~/.vim/skeleton.sh|normal G
184 " Lisp
185 autocmd BufNewFile *.lisp 0r ~/.vim/skeleton.lisp|normal G
186 " Markdown
187 autocmd BufNewFile *.mkd 0r ~/.vim/skeleton.mkd|normal G
188 
189 " Terminal {{{1
190 set mouse=a
191 " I almost use vim within a xterm compatible terminal (rxvt eg.)
192 set ttymouse=xterm
193 nmap <MiddleMouse> <Nop>
194 map <S-Insert> <MiddleMouse>
195 " I hate beeping (if your term is too slow: try rxvt :P)
196 set visualbell
197 
198 
199 " When on, the title of the window will be set to the value of 'titlestring'
200 set title
201 
202 " {{{1 vim7+ spell stuff
203 if version >= 700
204   " toggle spell on/off
205   map <F7> :set spell!<Cr>
206   imap <F7> <Esc>:set spell!<Cr>`]a
207 
208   " I'd like to use Ctrl-C like Escape
209   noremap <C-c> <Esc>
210 
211   " I prefer to turn on spellchecking via modeline or on demand
212   set nospell
213 
214   " I don't want modelines to be spellchecked
215   autocmd Syntax * syn region vimModeline start="\svim.\{-}:" end=+:+ display oneline transparent containedin=.*Comment.* contains=@NoSpell
216 
217 endif
218 
219 " abbreviations, nice shortcuts {{{1
220 " useful abbreviations for C coding
221 iab #i #include
222 iab #d #define
223 
224 " swap (transpose) two letters. 'ab' becomes 'ba'
225 nmap <silent> <LocalLeader>l xph
226 " swap (transpose) two words
227 nmap <silent> <LocalLeader>w "_yiw:s/\(\%#\w\+\)\(\W\+\)\(\w\+\)/\3\2\1/<cr><c-o>:nohlsearch<cr>
228 " show the syntax group of the char under the cursor
229 nmap <LocalLeader>s :echo synIDattr(synID(line("."), col("."), 1), "name")<cr>
230 nmap <LocalLeader>S :echo "hi<" . synIDattr(synID(line("."),col("."),1),"name") . "> trans<" . synIDattr(synID(line("."),col("."),0),"name") . "> lo<" . synIDattr(synIDtrans(synID(line("."),col("."),1)),"name") . ">"<cr>
231 
232 imap <silent> <C-Z> <Esc><C-Z>a
233 
234 " reindent the whole file
235 noremap <silent> <LocalLeader>i gg=G``
236 vnoremap <silent> <LocalLeader>i =
237 
238 " paste x11 clipboard content
239 noremap <silent> <LocalLeader>p "+p
240 
241 " I often type :Q/W instead of :q/w
242 command -bang Q q<bang>
243 command -bang Qa qa<bang>
244 " bar: The command can be followed by a "|" and another command
245 command -bang -bar -nargs=? -complete=file W w<bang> <args>
246 
247 " http://stackoverflow.com/questions/95072/what-are-your-favorite-vim-tricks
248 cmap w!! %!sudo tee > /dev/null %
249 
250 " toggle between matching of long lines and trailing whitespaces {{{2
251 " highlight whitespaces at EOL
252 autocmd Syntax * call MatchTrailingWhitespaces()
253 
254 highlight rightMargin term=bold ctermfg=blue guifg=blue
255 
256 noremap <silent> <LocalLeader>m :call ToggleMatch()<Cr>
257 
258 fun MatchTrailingWhitespaces()
259   match Error /\s\+$/
260   map <silent> <LocalLeader>t /\s\+$<Cr>
261   let g:MatchLongLines=0
262 endfun
263 
264 fun MatchLongLines()
265   match rightMargin /.\%>80v/
266   map <silent> <LocalLeader>t /\v(.%>80v)+<Cr>
267   let g:MatchLongLines=1
268 endfun
269 
270 fun ToggleMatch()
271   if !exists( "g:MatchLongLines" ) || g:MatchLongLines==0
272     call MatchLongLines()
273   elseif g:MatchLongLines==1
274     call MatchTrailingWhitespaces()
275   endif
276 endfun
277 
278 " this one is nice:  press ',u' to get the unicode name of the symbol under the cursor {{{2
279 " CREDITS: mgedmin on sf.net#vim
280 " EXAMPLE: go over this symbol: Ω and press ,u → it will print 'GREEK CAPITAL LETTER OMEGA'
281 if has('python')
282   nmap <silent> <LocalLeader>u :exec('py getUnicodeName()')<Cr>
283 python <<PYTHON
284 # -*- coding: utf-8 -*-
285 import vim, unicodedata
286 
287 def getUnicodeName():
288   try:
289     print unicodedata.name(vim.current.line[vim.current.window.cursor[1]:].decode('UTF-8')[0])
290   except IndexError, inst:
291     print "getUnicodeName():", inst
292 
293 PYTHON
294 endif
295 
296 " F5(make), F8(taglist), F9(numbering), F10(listchars) {{{1
297 noremap <F5> :make<Cr>
298 inoremap <F5> <Esc>:make<Cr>
299 
300 " toggle taglist (taglist plugin required!)
301 noremap <silent> <F6> :TlistToggle<Cr>
302 inoremap <silent> <F6> <Esc>:TlistToggle<Cr>`]a
303 
304 " toggle relative line numbers (RltvNmbr.vim plugin required)
305 " http://vim.sourceforge.net/scripts/script.php?script_id=2351
306 noremap <silent> <F8> :RN<Cr>
307 inoremap <silent> <F8> <Esc>:RN<Cr>`]a
308 
309 " use 'numberwidth' to set the number of columns for the line number
310 " toggle line numeration
311 noremap <silent> <F9> :set number!<Cr>
312 inoremap <silent> <F9> <Esc>:set number!<Cr>`]a
313 " however for some files I want line numbering by default
314 autocmd BufRead *known_hosts,*authorized_keys,*rc,*history set number
315 
316 " Remove whitespaces at EOL in the whole file
317 function TrimWhiteSpace()
318   %s/\s*$//
319 :endfunction
320 
321 noremap <F12> :call TrimWhiteSpace()<CR>
322 inoremap <F12> :call TrimWhiteSpace()<CR>
323 
324 " Highlight whitespaces at EOL
325 set listchars=tab:>-,trail:_,eol:$
326 "set listchars=tab:\ \ ,trail:_
327 noremap <silent> <F10> :set list!<Cr>
328 inoremap <silent> <F10> <Esc>:set list!<Cr>`]a
329 
330 set pastetoggle=<F11>
331 
332 " :TOhtml {{{1
333 let html_ignore_folding = 1
334 let html_number_lines = 1
335 let html_use_css = 1
336 let use_xhtml = 1
337 
338 " latex {{{1
339 " OPTIONAL: Starting with Vim 7, the filetype of empty .tex files defaults to
340 " 'plaintex' instead of 'tex', which results in vim-latex not being loaded.
341 " The following changes the default filetype back to 'tex':
342 let g:tex_flavor='latex'
343 
344 " plug-in settings {{{1
345 
346 " showmarks.vim plugin settings {{{2
347 " I want to enable showmarks on demand (using \mt)
348 let g:showmarks_enable=0
349 let g:showmarks_textlower=" "
350 let g:showmarks_textupper=" "
351 let g:showmarks_textother=" "
352 let g:showmarks_include="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
353 
354 
355 " omni completion {{{1
356 " disabled, because systags was 67mb large and hence much too slow
357 " do ctags -R -f ~/.vim/systags /usr/include /usr/local/include to tag system functions
358 " see :h ft-c-omni
359 " set tags+=~/.vim/systags
360 
361 " cscope {{{1
362 " if has("cscope")
363 "   set csprg=/usr/bin/cscope
364 "   set csto=0
365 "   set cst
366 "   set nocsverb
367 "   " add any database in current directory
368 "   if filereadable("cscope.out")
369 "     cs add cscope.out
370 "     " else add database pointed to by environment
371 "   elseif $CSCOPE_DB != ""
372 "     cs add $CSCOPE_DB
373 "   endif
374 "   set csverb
375 " endif
376 " }}}1
377 
378 if version >= 700
379   " function to go to the Most Recently Used (MRU) tab page
380   " like Ctrl-a Ctrl-a in screen does
381   " or Alt-Tab in the common window managers
382   au TabLeave * let g:MRUtabPage = tabpagenr()
383   fun MRUTab()
384     if exists( "g:MRUtabPage" )
385       exe "tabn " g:MRUtabPage
386     endif
387   endfun
388   noremap <silent> gl :call MRUTab()<Cr>
389 endif
390 
391 if !exists(':DiffOrig')
392   command DiffOrig vert new | set bt=nofile | r # | 0d_ | diffthis
393         \ | wincmd p | diffthis
394 endif
395 
396 " mark incorrect modelines (not closed with a colon)
397 autocmd Syntax * 2match Error "vim\d\{0,3}:\s\+set[^:]*$"
398 
399 " alternate file
400 " set timeout timeoutlen=250 ttimeoutlen=100
401 map <silent> <LocalLeader>h :A<Cr>
402 map <silent> <LocalLeader>as :AS<Cr>
403 map <silent> <LocalLeader>av :AV<Cr>
404 
405 if filereadable(".vimrc.host")
406   source .vimrc.host
407 endif
408 
409 " vim: set ft=vim fdm=marker fdl=0 fenc=utf-8 :
410 " vim700: set spelllang=en :