1 " vim: set ff=unix ai si noet ts=4 sw=4 fdls=1 fdm=marker wrap tw=0 sm mat=3 spell tags=$HOME/.vim/vimrc.tags :
3 " Terry M P<SNIP>, personal vimrc file
5 " $Id: .vimrc,v 1.11 2008/11/14 07:42:37 Terry Exp $:
7 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
8 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
10 " This file must have UNIX end of lines to avoid errors when starting
11 " under unix. Use the pdos2unix and punix2dos sh scripts to convert or
13 " perl -p -e 's/\n/\r\n/' inputfile > outputfile # UNIX to DOS
14 " perl -p -e 's/\r\n/\n/' inputfile > outputfile # DOS to UNIX
16 " on the command line or vim it self.
17 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
18 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
20 " |SETTINGS| --- Settings
21 " |GENERAL| --- General options
22 " |FORMATS| --- Configuration for various file formats
23 " |AUTOCMDS| --- Auto commands for calling format handler functions
24 " |HANDLERS| --- Handler functions for various file formats
25 " |INTERFACE| --- Interface specific settings
26 " |BINDS| --- Common Bindings
27 " |FUNCTIONS| --- Global helper functions
28 " |COMMANDS| --- Normal mode commands
29 " |MAPS| --- Key mappings
30 " |PLUGINS| --- Plugin specific configuration
33 " |play| --- Misc stuff, usually notes / code snippets
35 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
37 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
44 " Don't be VI compatible - Keep this at top of file !
45 " Also skip loading .exrc and friend sin the CWD.
49 " highlight matched text when searching
50 "if has('extra_search')
54 " Ignore case when searching unless it starts with a Capitol
58 " Use the system clipboard as the default register, '*'
60 set clipboard=unnamed,exclude:cons\|linux
63 " Make join commands smarter
69 " Allow names with some spaces in path, like when using gf
72 " Show matching symbols Vi style
75 set matchpairs=(:),{:},[:],<:>
77 " How to display tabs when list is on and expand tab is off
81 " Physical word wrapping
84 " Allow backspacing over everything in insert mode
85 set backspace=indent,eol,start
87 " Allow keys to move to next logical line marker at EOL
88 set whichwrap=b,s,h,l,<,>,[,],~
96 " Indentation settings (explictly)
101 " Set minimal length of line numbering
104 " Set tab menu 0=never, 1=when more then one, 2=always
107 " Preferred file formats, ffs
109 set fileformats=unix,dos,mac
112 " Show status bar with file name e.t.c.
113 " 0 = never, 1 = if >= 2 window, 2 = always
116 " Show % of file in status bar
117 if has("cmdline_info")
121 " Vim command line completion lists possible matches
122 set wildmode=list:full
124 " Start with mouse support in all modes
126 " Hide mouse pointer when typing in text
129 " Allow split windows to shrink to this size
132 " Set spell checker language
134 set spelllang=en_us,en_gb,de
136 " disable highlighting
137 " XXX see |MAPS| for a mapping to toggle this highlighting
138 set hl+=B:none,P:none,R:none,L:none
141 " Show function prototypes when doing ins-completion
144 " Settings for omni completion
145 if exists("+omnifunc")
148 "Enable syntax file based omni completion when no other method is set
151 \ if &omnifunc == "" |
152 \ setlocal omnifunc=syntaxcomplete#Complete |
157 " Allow cursor to move virtually in =mode or =onemore past the EOL
158 "set virtualedit=onemore
160 " UNIX: Include system tags file
162 set tags+=~/.vim/systags
165 " Enable filetypes and plugins
166 filetype plugin indent on
168 "Enable syntax related features
173 " Automatically change to directories if possible.
174 if has("netbeans_intg") || has("sun_workshop")
176 elseif has("autocmd")
177 " Mimic the autochdir option with a function and an autocmd
178 function! My_Autochdir()
181 autocmd BufEnter * call My_Autochdir()
192 " XXX Document based formats
193 " make *.txt dos/win friendly
194 autocmd BufNewFile *.txt set ff=dos
195 autocmd BufNewFile,BufRead *.txt call TextFileHandler()
196 autocmd BufNewFile *.rtf call RtfFileHandler()
197 autocmd BufRead *.rtf call RtfFileHandler()
198 autocmd BufRead *.doc call DocFileHandler()
199 autocmd BufRead *.pdf call PdfFileHandler()
200 autocmd BufRead *.ps call PsFileHandler()
201 autocmd BufRead *.dvi call DviFileHandler()
202 autocmd BufNewFile,BufRead *.outline call My_OutlineMode()
203 " XXX Image file based formats
204 autocmd BufRead *.jpg,*.jpeg,*.png,*.tiff,*.bmp,*.gif call ImgFileHandler()
205 autocmd BufRead *.xpm call XImgFileHandler()
206 " XXX Code based formats
207 autocmd filetype ada call AdaFileHandler()
208 autocmd filetype asm call AsmFileHandler()
209 autocmd BufNewFile,BufRead *.c,*.h call CFileHandler()
210 autocmd filetype css call CSSFileHandler()
211 autocmd BufNewFile,BufRead *.cc,*.cxx,*.cpp,*.hh,*.hpp,*.hxx call CXXFileHandler()
212 autocmd BufNewFile,BufRead *.d call DFileHandler()
213 autocmd BufNewFile,BufRead *.el call ELispFileHandler()
214 autocmd BufNewFile,BufRead *.html,*.xhtml call HtmlFileHandler()
215 autocmd filetype java call JavaFileHandler()
216 autocmd filetype javascript call JavaScriptFileHandler()
217 autocmd BufNewFile,BufRead *.lua call LuaFileHandler()
218 autocmd filetype make call MakefileFileHandler()
219 autocmd filetype perl call PerlFileHandler()
220 autocmd filetype php call PhpFileHandler()
221 autocmd filetype python call PythonFileHandler()
222 autocmd filetype ruby call RubyFileHandler()
223 autocmd filetype scheme call SchemeFileHandler()
224 autocmd filetype sh call ShellFileHandler()
225 autocmd filetype sql call SqlFileHandler()
226 autocmd filetype tex call TexFileHanlder()
227 autocmd filetype nroff call TroffFileHandler()
228 autocmd filetype vim call VimFileHanlder()
229 autocmd filetype vb call VisualBasicFileHandler()
230 " XXX for use with other programs
231 autocmd BufNewFIle,BUfRead *.tmp call My_KNodeConfig()
238 function! PreHandlerHook()
244 function! PostHandlerHook()
247 " XXX Document based formats
248 function! TextFileHandler()
249 call PreHandlerHook()
251 " turn off some stuff when viewing Vim help files
260 " fixes gq from using c-keyword based indentation
263 call PostHandlerHook()
266 function! RtfFileHandler()
267 call PreHandlerHook()
269 let l:prompt = input("View or edit % [yes|no]?: ")
270 if l:prompt=="y" || l:prompt=="yes" || l:prompt=="Y" || l:prompt=="YES"
271 !{abiword "%" || wordpad.exe "%" || kword "%" || swriter "%"} &
275 call PostHandlerHook()
278 function! DocFileHandler()
279 call PreHandlerHook()
281 if has("gui_running") || has("win32")
282 !{abiword "%" || kword "%" || swriter "%"} &
287 call PostHandlerHook()
290 function! PdfFileHandler()
291 call PreHandlerHook()
294 !{evince "%" || kpdf "%" || xpdf "%"} &
297 !"Foxit Reader.exe" "%" &
300 echo "No text dump program setup available...."
303 call PostHandlerHook()
306 function! PsFileHandler()
307 call PreHandlerHook()
309 let l:prompt = input("View or edit % [yes|no]?: ")
310 if l:prompt=="y" || l:prompt=="yes" || l:prompt=="Y" || l:prompt=="YES"
312 !{evince "%" || kpdf "%" || xpdf "%"} &
315 echo "Whats the ps viewer?"
317 echo "No text dump program installed...."
321 call PostHandlerHook()
324 function! DviFileHandler()
325 call PreHandlerHook()
327 let l:prompt = input("View % in Vim [yes|no]?: ")
328 if l:prompt=="y" || l:prompt=="yes" || l:prompt=="Y" || l:prompt=="YES"
329 " depends on the dvi2tty program
330 !dvi2tty -F'vim -c "setl ro fdl=99" -' "%"
334 !{xdvi "%" || kdvi "%" || "%"} &
337 !echo "Go look up how to open DVI on TexLive Win"
341 call PostHandlerHook()
344 " XXX Image file based formats
345 function! ImgFileHandler()
346 call PreHandlerHook()
352 !\%systemroot\%\system32\rundll32.exe \%systemroot\%\system32\shimgvw.dll,imageview_fullscreen "%" || \%systemroot\%\system32\mspaint.exe "%"
355 echo "no external viewer for text mode set...."
358 call PostHandlerHook()
361 function! XImgFileHandler()
362 call PreHandlerHook()
364 let l:prompt = input("View or edit % [yes|no]?: ")
365 if l:prompt=="y" || l:prompt=="yes" || l:prompt=="Y" || l:prompt=="YES"
372 call PostHandlerHook()
375 " XXX Code based formats
376 function! AdaFileHandler()
377 call PreHandlerHook()
379 call PostHandlerHook()
382 function! AsmFileHandler()
383 call PreHandlerHook()
388 call PostHandlerHook()
391 function! CFileHandler()
392 call PreHandlerHook()
394 setl tabstop=8 shiftwidth=8 noexpandtab
396 setl foldmethod=syntax foldcolumn=1
401 " modify cindent to understand my switch...case and paren style
402 setl cinoptions+=:2,=2,g2,(0
406 " highlight GNU Compiler stuff
408 " highlight preceding spaces before a tab as an error
410 let c_no_trail_space_error=1
411 " use C syntax in *.h rather then C++ syntax
415 " allow doxygen highlighting
419 call PostHandlerHook()
422 function! CSSFileHandler()
423 call PreHandlerHook()
425 setl tabstop=5 shiftwidth=5 expandtab
427 setl foldmethod=indent
430 call PostHandlerHook()
433 function! CXXFileHandler()
434 call PreHandlerHook()
436 setl tabstop=4 shiftwidth=4 expandtab
438 setl foldmethod=syntax foldcolumn=1
443 " modify cindent to understand my switch...case / class member
444 " access specifier / paren styles and not force #directives into
446 setl cinoptions+=:2,=2,g2,h2,(0,#1
451 " allow doxygen highlighting
452 set syntax=cpp.doxygen
455 call PostHandlerHook()
458 function! DFileHandler()
459 call PreHandlerHook()
460 call PostHandlerHook()
463 function! ELispFileHandler()
464 call PreHandlerHook()
465 call PostHandlerHook()
468 function! HtmlFileHandler()
469 call PreHandlerHook()
471 if has("syntax") && &t_Co > 2
475 setl tabstop=2 shiftwidth=2 expandtab
477 setl foldmethod=indent
480 if exists("+omnifunc") " think twice about using this with other langs
484 call PostHandlerHook()
487 function! JavaFileHandler()
488 call PreHandlerHook()
490 setl tabstop=4 shiftwidth=4 expandtab
492 setl foldmethod=indent
496 setl nospell " FUBAR in Java
498 " Highlight all identifiers in java.lang.*
499 let java_highlight_java_lang_ids=1
501 call PostHandlerHook()
504 function! JavaScriptFileHandler()
505 call PreHandlerHook()
507 call PostHandlerHook()
510 function! LuaFileHandler()
511 call PreHandlerHook()
512 call PostHandlerHook()
515 function! MakefileFileHandler()
516 call PreHandlerHook()
518 setl tabstop=4 shiftwidth=4 noexpandtab
520 setl foldmethod=indent
523 call PostHandlerHook()
526 function! PerlFileHandler()
527 call PreHandlerHook()
529 setl tabstop=4 shiftwidth=4 noexpandtab
531 setl foldmethod=indent
533 let perl_fold_blocks=1
537 call PostHandlerHook()
540 function! PhpFileHandler()
541 call PreHandlerHook()
543 setl tabstop=4 shiftwidth=4 expandtab
545 setl foldmethod=indent
546 " allow code folding for classes and functions!
550 " highlight HTML tags within strings
551 let php_htmlInStrings=1
553 let php_noShortTags=1
555 call PostHandlerHook()
558 function! PythonFileHandler()
559 call PreHandlerHook()
561 setl tabstop=4 shiftwidth=4 expandtab
563 setl foldmethod=marker
566 setl keywordprg=pydoc
568 let python_highlight_all=1
569 " slightly smarter indenting for (code\n morecode) situations
570 let g:pyindent_open_paren = '&sw + 1'
572 call PostHandlerHook()
575 function! RubyFileHandler()
576 call PreHandlerHook()
578 setl tabstop=2 shiftwidth=2 expandtab
580 setl foldmethod=syntax
587 call PostHandlerHook()
590 function! SchemeFileHandler()
591 call PreHandlerHook()
593 setl tabstop=4 shiftwidth=4 expandtab
595 setl foldmethod=syntax
599 setl nospell " FUBAR in Scheme
601 call PostHandlerHook()
604 function! ShellFileHandler()
605 call PreHandlerHook()
607 setl tabstop=4 shiftwidth=4 expandtab
609 setl foldmethod=indent
610 let g:sh_fold_enabled=8
614 call PostHandlerHook()
617 function! SqlFileHandler()
618 call PreHandlerHook()
619 " We almost always work with MySQL, so default to it.
621 setl tabstop=2 shiftwidth=2 expandtab
624 call PostHandlerHook()
627 function! TexFileHanlder()
628 call PreHandlerHook()
629 if has("syntax") && &t_Co > 2
634 setl tabstop=4 shiftwidth=4 softtabstop=4 noexpandtab
636 setl foldmethod=indent
637 " syntax-based folding of parts, chapters, sections, etc
638 let g:tex_fold_enabled=1
641 " fixes gq from using c-keyword based indentation
644 call PostHandlerHook()
647 function! TroffFileHandler()
648 call PreHandlerHook()
652 setl nospell " FUBAR in Java
655 call PostHandlerHook()
658 function! VimFileHanlder()
659 call PreHandlerHook()
661 if has("syntax") && &t_Co > 2
666 setl tabstop=4 shiftwidth=4 noexpandtab
668 setl foldmethod=marker
672 call PostHandlerHook()
675 function! VisualBasicFileHandler()
676 call PreHandlerHook()
678 "setl fileformat=unix
681 call PostHandlerHook()
684 " XXX for use with other programs
685 " Settings for outlining ideas
686 function! My_OutlineMode()
687 call PreHandlerHook()
689 setl tabstop=8 shiftwidth=8 noexpandtab
690 setl listchars =tab:\|\ " Mark \t's with |'s
696 if has("smartindent")
699 setl showmatch matchtime=3
700 setl matchpairs+=(:),{:},[:],<:>
703 "setl foldmethod=expr
704 "setl foldexpr=getline(v:lnum)[0]==\"\\t\"
706 setl foldmethod=marker
710 call PostHandlerHook()
713 " For the .tmp files created by knode
714 function! My_KNodeConfig()
715 call PreHandlerHook()
717 setl textwidth=0 wrap
722 if has('smartindent')
726 setl foldmethod=indent
730 call PostHandlerHook()
740 "set :command line height in lines
741 if has("gui_running")
748 " GUI: Set options mainly used for for GVim
750 " autoselect, console dialogs, tabpages, icon, menubar, show grey menu
751 " items, tearoff menu items, Toolbar, always right scrollbar.
752 set guioptions=aceimgtTr
754 " Right click menu lists correction options when spell is set
755 set mousemodel=popup_setpos
757 " Make mouse pointer an I-Beam in insert mode like most other programs
758 set mouseshape=i:beam
761 " X11: Specifics for GVim
764 set guifont=Terminus\ 14
768 " WINDOWS: Specifics for GVim
770 set guifont=Fixedsys:h11:cANSI
776 function! SetGuiColo() " {{{ XXX DEPRECIATED
778 if exists("*strftime")
779 let s:random = strftime("%S")
780 else " fall through to the else
877 function! SetConsoleColo() "{{{ XXX DEPRECIATED
880 " XXX override this for now
884 if exists("*strftime")
885 let s:random = strftime("%S")
886 else " fall through to the else
980 if !has("gui_running")
981 call SetConsoleColo()
993 " XXX: Be sure to add ! to functions and commands in order to overwrite
994 " the definitions if this file is resourced after startup.
997 " Make current file executable
998 function! ChmodScript()
999 silent! execute ":!chmod +x %"
1001 command! Chmod call ChmodScript()
1003 " ROT13 encode/decode the current file
1013 """" NEVER MAP THE BACKSPACE KEY OR A MODIFIER
1015 " Use ";" as an alias for ":" -> it makes life so much easier
1018 " show more data when we ask for a line count
1019 nnoremap <C-g> <C-g>2<C-g>
1021 " clear search highlighting when redrawing the screen
1022 nnoremap <silent> <C-l> :nohl<CR><C-l>
1024 " Make Escape toggle normal/insert mode -> I don't like this!
1025 "nnoremap <silent> <esc> :startinsert<CR>
1027 " Combine [s and ]s with z=
1028 " (e.g. move to miss spelled word in direction and get suggestions)
1032 " toggle spelling highlights on/off
1033 nnoremap <leader>Z :set hl&<cr>
1034 nnoremap <leader>z :set hl+=B:none,P:none,R:none,L:none<cr>
1036 " swap words under cursor with \xp or \gw (where \ = <leader>
1037 noremap <silent> <leader>xp "_yiw:s/\(\%#\w\+\)\(\W\+\)\(\w\+\)/\3\2\1/<cr><c-o><c-l>
1038 noremap <silent> <leader>gw <leader>xp
1040 " Use emacs style movement commands in insert mode
1041 " XXX: these redine Vim maps, ctrl-a => useless, ctrl-e => useful
1042 "inoremap <c-a> <esc>I
1043 "inoremap <c-e> <esc>A
1045 " F1 toggles spell checking for this buffer
1047 inoremap <F1> <esc>:set spell! <bar> set spell?<CR>i
1048 nnoremap <F1> <esc>:set spell! <bar> set spell?<CR>
1051 " F2 toggles line numbers
1052 nnoremap <F2> :set number! <bar> set number?<CR>
1053 inoremap <F2> <esc>:set number! <bar> set number?<CR>i
1055 " F3 turns on auto indentations
1056 nnoremap <F3> :set smartindent autoindent<CR>
1057 inoremap <F3> <esc>:set smartindent autoindent<CR>i
1059 " XXX make this toggle the nerd tree plugin
1060 " F5 launches file manager in the current directory
1061 nnoremap <F5> :OPEN %:p:h<CR>
1062 inoremap <F5> <esc>:OPEN %:p:h<CR>i
1072 map <silent><leader>tl :TlistToggle<CR>
1073 let g:Tlist_Auto_Open=0
1074 let g:Tlist_GainFocus_On_ToggleOpen=1
1075 let g:Tlist_Enable_Fold_Column=0
1076 let g:Tlist_Exit_OnlyWindow=1
1077 let g:Tlist_Display_Prototype=1
1078 let g:Tlist_Show_Menu=1
1091 " Beautify omnicompletion popup
1092 "highlight Pmenu guifg=white guibg=blue ctermfg=white ctermbg=blue
1096 " set foldexpr=getline(v:lnum)=~'^\\s*$'&&getline(v:lnum+1)=~'\\S'?'<1':1
1099 if exists("*strftime")
1100 iabbrev insert_date <c-r>=strftime("%Y-%m-%d %H:%M:%S")<cr>
1104 iabbrev swtich switch