" from http://bwaldvogel.de/rc/vim.html
" the XHTML files are generated using :%TOhtml
"
" also an excellent vimrc:
" http://www.jukie.net/~bart/conf/vimrc
"
" nice blog post:
" http://items.sjbach.com/319/configuring-vim-right
"
" startup benchmarks
"
" • vim-7.1.028
" # time vim -cq
" vim -cq 0.25s user 0.02s system 88% cpu 0.302 total
" • vim-7.1.042
" # 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 → €
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=','
" no, I don't like that - it's too much
" set laststatus=2
" set statusline=%<%F%=\ [%1*%M%*%n%R%H%Y]\ \ %-25(%3l,%c%03V\ \ %P\ (%L)%)%12o'%03b''%03B'
" 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
" • pablo
" • torte
" • desert256
hi StatusLine ctermfg=black ctermbg=white
" {{{1 Python
" I want all possible Python highlighting (see ft-python-syntax)
let python_highlight_all=1
au FileType python source ~/.vim/scripts/python.vim
" {{{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
"Comments {{{1
vmap c VisualTraditional
nmap c Traditional
" don't create mapping for the insert mode
let g:EnhCommentifyBindInInsert = 'No'
let g:EnhCommentifyMultiPartBlocks = 'Yes'
let g:EnhCommentifyPretty = 'Yes'
let g:EnhCommentifyRespectIndent = 'Yes'
let g:EnhCommentifyUseBlockIndent = 'Yes'
" New filetypes (callback since EC v2.3)
function EnhCommentifyCallback(ft)
if a:ft =~ '\v(gentoo-package-(keywords|use|(un)?mask)|cmake)'
let b:ECcommentOpen = '#'
let b:ECcommentClose = ''
endif
endfunction
let g:EnhCommentifyCallbackExists = 'Yes'
" 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
" useful abbreviations for C coding
iab #i #include
iab #d #define
" 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 synIDattr(synID(line("."), col("."), 1), "name")
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
noremap i gg=G``
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
noremap :call TrimWhiteSpace()
inoremap :call TrimWhiteSpace()
" Highlight whitespaces at EOL
set listchars=tab:>-,trail:_,eol:$
"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"
" 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
" }}}1
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 :