2011/04/25

Vim Config

" Last update: 2011-04-25
"
" {{{ function! GuiTabLabel()
" set up tab labels with tab number, buffer name, number of windows
function! GuiTabLabel()
  let label = ''
  let bufnrlist = tabpagebuflist(v:lnum)

  " Add '+' if one of the buffers in the tab page is modified
  for bufnr in bufnrlist
    if getbufvar(bufnr, "&modified")
      let label = '+'
      break
    endif
  endfor

  " Append the tab number
  let label .= v:lnum.': '

  " Append the buffer name
  let name = bufname(bufnrlist[tabpagewinnr(v:lnum) - 1])
  if name == ''
    " give a name to no-name documents
    if &buftype=='quickfix'
      let name = '[Quickfix List]'
    else
      let name = '[No Name]'
    endif
  else
    " get only the file name
    let name = fnamemodify(name,":t")
  endif
  let label .= name

  " Append the number of windows in the tab page
  let wincount = tabpagewinnr(v:lnum, '$')
  return label . '  [' . wincount . ']'
endfunction
" }}}

" {{{ function! GuiTabToolTip()
" set up tab tooltips with every buffer name
function! GuiTabToolTip()
  let tip = ''
  let bufnrlist = tabpagebuflist(v:lnum)

  for bufnr in bufnrlist
    " separate buffer entries
    if tip!=''
      let tip .= ' | '
    endif

    " Add name of buffer
    let name=bufname(bufnr)
    if name == ''
      " give a name to no name documents
      if getbufvar(bufnr,'&buftype')=='quickfix'
        let name = '[Quickfix List]'
      else
        let name = '[No Name]'
      endif
    endif
    let tip.=name

    " add modified/modifiable flags
    if getbufvar(bufnr, "&modified")
      let tip .= ' [+]'
    endif
    if getbufvar(bufnr, "&modifiable")==0
      let tip .= ' [-]'
    endif
  endfor

  return tip
endfunction
" }}}

syntax on
filetype plugin indent on
colors koehler

" {{{ Set Variables
" set guifont=Monaco\ 12
" set guifont=Mono\ 13
set guifont=WenQuanYi\ Zen\ Hei\ Mono\ 13
set tabstop=4
set softtabstop=4
set shiftwidth=4
set textwidth=0
set selectmode=mouse
set foldmethod=marker
set backspace=start,indent,eol
set guioptions-=m
set guioptions-=T
set guioptions-=r
set guioptions-=R
set guioptions-=l
set guioptions-=L
set showtabline=2
set nocompatible
set cindent
set number
set incsearch
set cursorline
set hlsearch
set guitablabel=%{GuiTabLabel()}
set guitabtooltip=%{GuiTabToolTip()}
set history=1000
" }}}

" Automatically reload .vimrc after changing it
autocmd! bufwritepost .vimrc source %

" Automatically activate word completion
"autocmd! BufEnter * call DoWordComplete()

" {{{ Showmarks
hi ShowMarksHLl ctermbg=Yellow   ctermfg=Black  guibg=#FFDB72    guifg=Black
hi ShowMarksHLu ctermbg=Magenta  ctermfg=Black  guibg=#FFB3FF    guifg=Black
let showmarks_include="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
let g:showmarks_hlline_lower=1
let g:showmarks_hlline_upper=1
" }}}

" {{{ Map key bindings
map     <silent><C-S-w>w :tabc<CR>
map     <silent><C-S-t>t :tabnew<CR>
nmap    <silent><leader>[ :tabp<CR>
nmap    <silent><leader>] :tabn<CR>
nmap    <silent><leader>mktags :!ctags -R --extra=+fq --fields=+i --PHP-kinds=+cidfv .<CR>
nmap    <silent><leader>mb :MarksBrowser<CR>
nmap    <silent><leader>fc :FufCoverageFile<CR>
imap    <silent><C-\> <C-x><C-o>
" }}}

" {{{ Omni CPP Complete
let OmniCpp_SelectFirstItem = 1
autocmd CursorMovedI * if pumvisible() == 0|pclose|endif
autocmd InsertLeave * if pumvisible() == 0|pclose|endif
" }}}

" {{{ Fold and Unfold source codes
function! Fold_Source_Code()
    normal yyPi# {{{
    normal jj%o# }}}
endfunction

function! Unfold_Source_Code()
    normal ddj%jddk%k
endfunction
" }}}

" FencView
" Co-work with Netrw
"let g:fencview_autodetect = 0

" Make Shift+Insert behaves just like in Xterm
imap <S-Insert> <MiddleMouse>

" {{{ CScope helper
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
    set cscopetag
    set cscopequickfix=s-,g-,c-,d-,t-,e-,f-,i-

    " Map key bindings
    nmap <C-\> <C-_>g
    nmap <C-_>s :cs find s <C-R>=expand("<cword>")<CR><CR><C-o>:tabnew<CR>:copen<CR><C-w>4-<CR>
    nmap <C-_>g :cs find g <C-R>=expand("<cword>")<CR><CR><C-o>:tabnew<CR>:copen<CR><C-w>4-<CR>
    nmap <C-_>c :cs find c <C-R>=expand("<cword>")<CR><CR><C-o>:tabnew<CR>:copen<CR><C-w>4-<CR>
    nmap <C-_>t :cs find t <C-R>=expand("<cword>")<CR><CR><C-o>:tabnew<CR>:copen<CR><C-w>4-<CR>
    nmap <C-_>e :cs find e <C-R>=expand("<cword>")<CR><CR><C-o>:tabnew<CR>:copen<CR><C-w>4-<CR>
    nmap <C-_>f :cs find f <C-R>=expand("<cword>")<CR><CR><C-o>:tabnew<CR>:copen<CR><C-w>4-<CR>
    nmap <C-_>i :cs find i <C-R>=expand("<cword>")<CR><CR><C-o>:tabnew<CR>:copen<CR><C-w>4-<CR>
    nmap <C-_>d :cs find d <C-R>=expand("<cword>")<CR><CR><C-o>:tabnew<CR>:copen<CR><C-w>4-<CR>
endif
" }}}

" {{{ VIM -b : edit binary using xxd-format!
augroup Binary
  au!
  au BufReadPre  *.bin let &bin=1
  au BufReadPost *.bin if &bin | %!xxd
  au BufReadPost *.bin set ft=xxd | endif
  au BufWritePre *.bin if &bin | %!xxd -r
  au BufWritePre *.bin endif
  au BufWritePost *.bin if &bin | %!xxd
  au BufWritePost *.bin set nomod | endif
augroup END
" }}}

filetype off
call pathogen#runtime_append_all_bundles()
filetype plugin indent on