" from http://bwaldvogel.de/rc/vim.html " the XHTML files are generated using :%TOhtml " " other excellent vimrcs: " https://github.com/sjl/dotfiles/blob/master/vim/.vimrc " http://www.jukie.net/~bart/conf/vimrc " " nice blog post: " http://items.sjbach.com/319/configuring-vim-right " " startup benchmarks " " Tip: vim --startuptime startup.log " " • vim-7.3.266 [desktop] " # time vim -cq " vim -cq 0,10s user 0,00s system 97% cpu 0,106 total " • vim-7.1.028 [laptop] " # time vim -cq " vim -cq 0.25s user 0.02s system 88% cpu 0.302 total " • vim-7.1.042 [laptop] " # time vim -cq " vim -cq 0.09s user 0.01s system 95% cpu 0.101 total " " use :help in case you don't know what something stands for " Tricks: " " 1. enumerate lines in block mode " C-v !cat -n " or better use VisIncr → c-V :I [#] " " 2. insert unicode characters " u20ac → € " let g:omni_sql_no_default_maps = 1 set nocompatible set showcmd " be careful: tabs may look different on other systems set tabstop=4 set shiftwidth=4 set autoindent set smartindent " don't go to the start of line when doing G etc. set nosol " recognize lines as you can see at the bottom set modeline set modelines=3 " don't insert TWO spaces after '.', '?' etc. when joining lines set nojoinspaces " do macros, do them FAST! set lazyredraw " pop a completion list when pressing (like zsh does...) set wildmenu " have the completion similar to shell completion set wildmode=list:longest set wildignore=*.class,*.o,*.bak,*.swp,*.tmp,*.part " display also the hexcode of the char under the cursor set rulerformat=0x%02B\ %3p%%\ %l,%c%V " allways show the ruler set ruler " don't give the intro message when starting set shortmess+=I let maplocalleader=',' " allow backspacing over autoindent, line breaks (join lines), " the start of insert; CTRL-W and CTRL-U stop once at the start of insert. set backspace=indent,eol,start " debugging {{{1 " set verbosefile=/tmp/vim.verbose " set verbose=100 " {{{1 highlighting " see ~/.vim/after/syntax/syncolor.vim too syntax on " color scheme for dark backgrounds >:) set background=dark " :so $VIMRUNTIME/syntax/hitest.vim " I configure my screen with --enable-colors256 (Gentoo does this by default!) if $TERM =~ '^screen' | set t_Co=256 | endif " I use a patched rxvt-unicode which is able to display 256 colors if $TERM =~ '^rxvt-unicode' | set t_Co=256 | endif if $TERM =~ '^xterm' | set t_Co=256 | endif if &t_Co >= 256 try colorscheme 256asu1black catch colorscheme pablo endtry else colorscheme pablo endif " favourite colorschemes: " • 256_asu1dark " • solarized " • pablo " • torte " • desert256 " let g:solarized_termcolors=256 " statusline {{{1 " https://twitter.com/#!/grantlucas/statuses/111827076373422082 " https://bitbucket.org/sjl/dotfiles/src/2e25b11e75fc/vim/.vimrc#cl-86 set laststatus=2 set statusline+=\ " Space for padding on left side set statusline+=%< " Truncate on the left side of text if too long set statusline+=%t " File name (Tail) set statusline+=%r " Readonly Flag set statusline+=%m " Modified Flag set statusline+=\ " Space set statusline+=%#warningmsg# " Set warning highlighting set statusline+=%{SyntasticStatuslineFlag()} " Show syntax errors provided by syntastic plugin set statusline+=%* " clear highlighting set statusline+=%= " Right Align set statusline+=%{SynGroup()} " Show current syntax group set statusline+=\ " Space set statusline+=%{ShowSpell()} " Show whether or not spell is currently on set statusline+=\ " Space set statusline+=%{ShowWrap()} " Show whether or not wrap is currently on set statusline+=\ " Space set statusline+=%{fugitive#statusline()} " Git branch name courtesy of Fugitive plugin set statusline+=%w " Preview window flag set statusline+=\ " Space set statusline+=%{&ff} " Format of file set statusline+=/ set statusline+=%{strlen(&fenc)?&fenc:&enc} " Encoding of file set statusline+=/ set statusline+=%{&ft} " Type of file set statusline+=\ " Space set statusline+=0x%02B " Hex of current symbol set statusline+=\ " Space set statusline+=(%l/%L,%c%V) " Current position and line count set statusline+=\ " Space set statusline+=%P " Percent set statusline+=\ " Space for padding on right side function! SynGroup() return synIDattr(synID(line("."), col("."), 1), "name") endfunction function! ShowWrap() if &wrap return "[Wrap]" else return "" endfunction function! ShowSpell() if &spell return "[Spell]" else return "" endfunction hi StatusLine ctermfg=white ctermbg=236 hi StatusLineNC ctermfg=247 ctermbg=236 " swap statusline colors in insert mode " inspired by https://twitter.com/#!/dotvimrc/statuses/114358110054920192 au InsertEnter * hi StatusLine ctermfg=236 ctermbg=white au InsertLeave * hi StatusLine ctermfg=white ctermbg=236 " {{{1 Python " I want all possible Python highlighting (see ft-python-syntax) let python_highlight_all=1 " {{{1 folding (see :h folding) " show all folds closed set foldenable " fold on markers tripple { set foldmethod=marker autocmd FileType c,cpp,d,perl,java,cs set foldmethod=syntax autocmd FileType python set foldmethod=indent set foldcolumn=1 set foldlevel=99 " http://vim.wikia.com/wiki/Auto-fold_Perl_subs let perl_fold=1 let perl_fold_blocks=1 "Comments {{{1 " add new filetypes: autocmd FileType apache,gitcommit set commentstring=#\ %s vmap c Commentary nmap c CommentaryLine " searching {{{1 " highlight search set hls " higlight while searching set incsearch " search for upper and lowercase set ignorecase " but if user types uppercase - search exactly set smartcase nmap n :nohlsearch " Files (types, skeletons, indenting) {{{1 " detect filetypes and turn on indentation (cindent for c files e.g.) filetype plugin indent on " break c/c++/perl/python/java after 80 lines " comments only, but it depends on 'formatoptions' " Indenting in source files autocmd FileType c,cpp,cs,d,html,java,perl,php,python,shell,vim,xhtml,xml,xslt,xsl set tabstop=2 shiftwidth=2 noexpandtab " automatic detection of et,sw,ts setting with script #1171 " autocmd BufReadPost * :DetectIndent " skeletons {{{2 " perl autocmd BufNewFile *.pl 0r ~/.vim/skeleton.pl|normal G " python autocmd BufNewFile *.py 0r ~/.vim/skeleton.py|normal G " C autocmd BufNewFile *.c 0r ~/.vim/skeleton.c|normal G " C++ autocmd BufNewFile *.cpp 0r ~/.vim/skeleton.cpp|normal G " D autocmd BufNewFile *.d 0r ~/.vim/skeleton.d|normal G " (X)HTML autocmd BufNewFile *.html 0r ~/.vim/skeleton.html|normal GddA autocmd BufNewFile *.xhtml,*.shtml 0r ~/.vim/skeleton.xhtml|set ft=xhtml|normal G " XML autocmd BufNewFile *.xml 0r ~/.vim/skeleton.xml|normal G " XSL autocmd BufNewFile *.xsl 0r ~/.vim/skeleton.xsl|normal 2j26| " Shell autocmd BufNewFile *.sh 0r ~/.vim/skeleton.sh|normal G " Lisp autocmd BufNewFile *.lisp 0r ~/.vim/skeleton.lisp|normal G " Markdown autocmd BufNewFile *.mkd 0r ~/.vim/skeleton.mkd|normal G " Terminal {{{1 set mouse=a " I almost use vim within a xterm compatible terminal (rxvt eg.) set ttymouse=xterm nmap map " I hate beeping (if your term is too slow: try rxvt :P) set visualbell " When on, the title of the window will be set to the value of 'titlestring' set title " {{{1 vim7+ spell stuff if version >= 700 " toggle spell on/off map :set spell! imap :set spell!`]a " I'd like to use Ctrl-C like Escape noremap " I prefer to turn on spellchecking via modeline or on demand set nospell " I don't want modelines to be spellchecked autocmd Syntax * syn region vimModeline start="\svim.\{-}:" end=+:+ display oneline transparent containedin=.*Comment.* contains=@NoSpell endif " abbreviations, nice shortcuts {{{1 " swap (transpose) two letters. 'ab' becomes 'ba' nmap l xph " swap (transpose) two words nmap w "_yiw:s/\(\%#\w\+\)\(\W\+\)\(\w\+\)/\3\2\1/:nohlsearch " show the syntax group of the char under the cursor nmap s :echo SynGroup() nmap S :echo "hi<" . synIDattr(synID(line("."),col("."),1),"name") . "> trans<" . synIDattr(synID(line("."),col("."),0),"name") . "> lo<" . synIDattr(synIDtrans(synID(line("."),col("."),1)),"name") . ">" imap a " reindent the whole file (and restore position) noremap i msHmtgg=G``'tzt`s vnoremap i = " paste x11 clipboard content noremap p "+p " I often type :Q/W instead of :q/w command -bang Q q command -bang Qa qa " bar: The command can be followed by a "|" and another command command -bang -bar -nargs=? -complete=file W w " http://stackoverflow.com/questions/95072/what-are-your-favorite-vim-tricks cmap w!! %!sudo tee > /dev/null % " toggle between matching of long lines and trailing whitespaces {{{2 " highlight whitespaces at EOL autocmd Syntax * call MatchTrailingWhitespaces() highlight rightMargin term=bold ctermfg=blue guifg=blue noremap m :call ToggleMatch() fun MatchTrailingWhitespaces() match Error /\s\+$/ map t /\s\+$ let g:MatchLongLines=0 endfun fun MatchLongLines() match rightMargin /.\%>80v/ map t /\v(.%>80v)+ let g:MatchLongLines=1 endfun fun ToggleMatch() if !exists( "g:MatchLongLines" ) || g:MatchLongLines==0 call MatchLongLines() elseif g:MatchLongLines==1 call MatchTrailingWhitespaces() endif endfun " this one is nice: press ',u' to get the unicode name of the symbol under the cursor {{{2 " CREDITS: mgedmin on sf.net#vim " EXAMPLE: go over this symbol: Ω and press ,u → it will print 'GREEK CAPITAL LETTER OMEGA' if has('python') nmap u :exec('py getUnicodeName()') python < :make inoremap :make " toggle taglist (taglist plugin required!) noremap :TlistToggle inoremap :TlistToggle`]a " toggle relative line numbers (RltvNmbr.vim plugin required) " http://vim.sourceforge.net/scripts/script.php?script_id=2351 noremap :RN inoremap :RN`]a " use 'numberwidth' to set the number of columns for the line number " toggle line numeration noremap :set number! inoremap :set number!`]a " however for some files I want line numbering by default autocmd BufRead *known_hosts,*authorized_keys,*rc,*history set number " Remove whitespaces at EOL in the whole file function TrimWhiteSpace() %s/\s*$// :endfunction " see :he restore-position noremap msHmt:call TrimWhiteSpace()'tzt`s inoremap msHmt:call TrimWhiteSpace()'tzt`s set listchars=tab:▸\ ,trail:_,eol:¬,extends:❯,precedes:❮ "set listchars=tab:\ \ ,trail:_ noremap :set list! inoremap :set list!`]a set pastetoggle= " :TOhtml {{{1 let html_ignore_folding = 1 let html_number_lines = 1 let html_use_css = 1 let use_xhtml = 1 " latex {{{1 " OPTIONAL: Starting with Vim 7, the filetype of empty .tex files defaults to " 'plaintex' instead of 'tex', which results in vim-latex not being loaded. " The following changes the default filetype back to 'tex': let g:tex_flavor='latex' " plug-in settings {{{1 " showmarks.vim plugin settings {{{2 " I want to enable showmarks on demand (using \mt) let g:showmarks_enable=0 let g:showmarks_textlower=" " let g:showmarks_textupper=" " let g:showmarks_textother=" " let g:showmarks_include="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" " closetag.vim plugin settings {{{2 let b:closetag_html_style=1 " omni completion {{{1 " disabled, because systags was 67mb large and hence much too slow " do ctags -R -f ~/.vim/systags /usr/include /usr/local/include to tag system functions " see :h ft-c-omni " set tags+=~/.vim/systags " cscope {{{1 " if has("cscope") " set csprg=/usr/bin/cscope " set csto=0 " set cst " set nocsverb " " add any database in current directory " if filereadable("cscope.out") " cs add cscope.out " " else add database pointed to by environment " elseif $CSCOPE_DB != "" " cs add $CSCOPE_DB " endif " set csverb " endif " plugins {{{1 " syntactics let g:syntastic_enable_signs=1 " pathogen " http://www.vim.org/scripts/script.php?script_id=2332 " http://github.com/tpope/vim-pathogen runtime bundle/tpope-vim-pathogen/autoload/pathogen.vim call pathogen#infect() " gundo " http://briancarper.net/blog/573/vim-undo-tree-visualization " https://bitbucket.org/sjl/gundo.vim/ nnoremap z :GundoToggle " }}}1 " calculator (http://www.unfug.org/data/foils/ss10/vimrc) ino yiW==0 if version >= 700 " function to go to the Most Recently Used (MRU) tab page " like Ctrl-a Ctrl-a in screen does " or Alt-Tab in the common window managers au TabLeave * let g:MRUtabPage = tabpagenr() fun MRUTab() if exists( "g:MRUtabPage" ) exe "tabn " g:MRUtabPage endif endfun noremap gl :call MRUTab() endif if !exists(':DiffOrig') command DiffOrig vert new | set bt=nofile | r # | 0d_ | diffthis \ | wincmd p | diffthis endif " mark incorrect modelines (not closed with a colon) autocmd Syntax * 2match Error "vim\d\{0,3}:\s\+set[^:]*$" " alternate file " set timeout timeoutlen=250 ttimeoutlen=100 map h :A map as :AS map av :AV if filereadable(".vimrc.host") source .vimrc.host endif " vim: set ft=vim fdm=marker fdl=0 fenc=utf-8 : " vim700: set spelllang=en :