Wednesday, September 24, 2008

my vimrc

""script by Lifeng Chen.
set langmenu=en_US
let $LANG = 'en_US'
syntax on
set nocompatible
set ai
set textwidth=0 ""disable line auto broken
set hlsearch
set incsearch
set magic
"set scrolloff=3 ""to see more context above and below the cursor
set lz " do not redraw while running macros (much faster) (LazyRedraw)
"set shell=csh\ -f
if has("win32")
set backupdir=c:/tmp/vim
set guifont=Lucida_Console:h11:b:cANSI
let myfile = $VIMRUNTIME."/colors/my_murphy.vim"
else
set backupdir=~/tmp/vim
set guifont=MiscFixed\ 12
"set guifont=MiscFixed\ Bold\ 11
let myfile = $HOME."/.vim/colors/my_murphy.vim"
endif
if filereadable(myfile)
colorscheme my_murphy
else
colorscheme murphy
endif
so $VIMRUNTIME/mswin.vim
"set nu ""disable line_number for TERM as it is not intended when copying
set vb t_vb= ""disable any boring beep or flash. Need to set in .gvimrc to make it really work for GUI.
"set autochdir ""don't change working dir automatically for TERM
set nowrap
set backup ""I also need non-default backupdir
set viminfo='10,:20,%,n~/.viminfo ""same viminfo: 'files w marks, :cmd his num,
"set mouse=a
"set mouse=nvc
"set mousemodel=extend
"set nowrapscan
set more
set ve=block
set vb t_vb= " no beep or flash
set fillchars=stl:^,stlnc:-,vert:\|,fold:-,diff:- " better spacing btwn windows

set showmatch "" When a bracket is inserted, briefly jump to the matching one.
set matchtime=5
set wildignore=.svn,CVS,.git,*.o,*.a,*.class,*.mo,*.la,*.so,*.obj,*.swp,*.jpg,*.png,*.xpm,*.gif
set wildmode=list:full "" Completion mode: When more than one match, list all matches and complete first match.
set wildmenu "" command-line completion operates in an enhanced mode: to invoke the completion
" syn keyword myTodo todo contained
" highlight def link myTodo Todo
"" highlight my favorites
match Todo /\c\\|\\|\/

set ru "" Show the line and column number of the cursor position
if version >= 700
set cul "" Highlight the screen line of the cursor with CursorLine
endif
"set cuc "" Highlight the screen column of the cursor with CursorColumn
"" a: Autoselect, Visually highlighted text is available for pasting into other applications as well as into Vim itself
"" b: Bottom (horizontal) scrollbar is present
set guioptions+=abrh
set guioptions-=L "" L: Left-hand scrollbar is present when there is a vertically
set foldmethod=indent
set foldlevelstart=1
"let b:did_ftplugin = 1 ""This disables loading of default plugin completely
autocmd FileType python source ~/.vim/ftplugin/python.vim
"" {{{balloon control
if version >= 700
set ballooneval "" ballon control
fun! FoldSpellBalloon()
let foldStart = foldclosed(v:beval_lnum )
let foldEnd = foldclosedend(v:beval_lnum)
let lines = []
let maxlinenum=60
" Detect if we are in a fold
if foldStart < 0
" Detect if we are on a misspelled word
let lines = spellsuggest( spellbadword(v:beval_text)[ 0 ], 5, 0 )
else
" we are in a fold
let numLines = foldEnd - foldStart + 1
" if we have too many lines in fold, show only the first half_of_max
" and the last half_of_max lines
if ( numLines >= maxlinenum )
let lines = getline( foldStart, foldStart + maxlinenum/2 - 1 )
let lines += [ '..............' ]
let lines += [ '[-- Snipped ' . ( numLines - maxlinenum ) . ' lines --]' ]
let lines += [ '..............' ]
let lines += getline( foldEnd - maxlinenum/2 + 1, foldEnd )
else
"less than maxlinenum lines, lets show all of them
let lines = getline( foldStart, foldEnd )
endif
endif
" return result
return join( lines, has( "balloon_multiline" ) ? "\n" : " " )
endfun
set balloonexpr=FoldSpellBalloon()
set balloondelay=400
"" settings invalid for the KDE, GTK+ or Win32
"set tooltipForeground=
"set tooltipBackground=
"set tooltipFont=
"set balloonevalcode 59
endif
""}}}balloon control

function! ShortStr(str,max_len)
let max_len_lead = a:max_len/2
let total_len=strlen(a:str)
let trim_str = a:str
if total_len > a:max_len
let trim_str = strpart(a:str, 0, max_len_lead) . ".." . strpart(a:str, total_len - a:max_len + max_len_lead + 2)
endif
return trim_str
endfunction
function! CurDir()
let homedir = '/home/'.$USER
let curdir = substitute(getcwd(), homedir, "~", "g")
let curdir=ShortStr(curdir, 18)
return curdir . "/"
endfunction
"set ruler "" overridden by statusline ""Show the line and column number of the cursor position
"set rulerformat=%20(%2*%<%f%=" %m%r" %3l" %c" %p%%%)
"" {{{statusline control
if filereadable(myfile)
"set statusline=%F%m%r%h%w" [FORMAT=%{&ff}]" [TYPE=%Y]" [POS=%l,%v][%p%%]" %{strftime(""%d/%m/%y" -" %H:%M"")}
"set statusline=%F%m%r%h%w\ [FORMAT=%{&ff}]\ [TYPE=%Y]\ [ASCII=\%03.3b]\ [HEX=\%02.2B]\ [POS=%04l,%04v][%p%%]\ [LEN=%L]
"set statusline=%F%m%r%h%w\ -\ ascii=x\%02.2B,\ pos=%05l,%3v\ (%p%%\ of\ %L\ lines)
set statusline= ""overwrite any existent statusline
set statusline+=%#StatusLineB1#%f%m%r%h%w%0* ""short name
set statusline+=%#StatusLineB2#[BUF:%-1.2n]%0* ""buffer number
set statusline+=%#StatusLineB3#[%{&fileformat}]%0* ""fileformat
set statusline+=%= ""spacer
"set statusline+=%#StatusLineB3#[%{CurDir()}]%0* ""fileformat
set statusline+=%#StatusLineB4#[%p%%]%0* ""position percentage
set statusline+=%#StatusLineB5#[pos=%05l,%3v]%0* ""horizontal/vertical position
set statusline+=%#StatusLineB6#[LEN=%L]%0* ""total line number
set statusline+=%< ""Left aligned to see file name all the time
set laststatus=2 "" 2: the last window will always have a status line
else
set statusline= ""overwrite any existent statusline
set statusline+=%f%m%r%h%w%0* ""short name
set statusline+=[BUF:%-1.2n]%0* ""buffer number
set statusline+=[%{&fileformat}]%0* ""fileformat
set statusline+=%= ""spacer
set statusline+=[%p%%]%0* ""position percentage
set statusline+=[pos=%05l,%3v]%0* ""horizontal/vertical position
set statusline+=[LEN=%L]%0* ""total line number
set statusline+=%< ""Left aligned to see file name all the time
set laststatus=2 "" 2: the last window will always have a status line
endif
""}}}statusline control

"--------------------------------------for mapping-------------------------------
let mapleader = ","
"{{{
"" fast switch btwn buffers
nnoremap gt
nnoremap gT
nnoremap w
nnoremap h
nnoremap l
nnoremap j
nnoremap k
"" za: open or close a fold
"" zA: open or close a fold recursively
nnoremap za
nnoremap zA

if version >= 700
"open file in new tabpage
vnoremap gf y:sp =escape(@", '\\/.*$^~[]')
nnoremap gf
endif

"" fast search: don't use as I want them echoed
nnoremap / yiw/=escape(@", '\\/.*$^~[]')
nnoremap /b /\<\>
nnoremap /c /\c
nnoremap /e //e
nnoremap /
nnoremap ?
vnoremap y/=escape(@", '\\/.*$^~[]')q
vnoremap y?=escape(@", '\\/.*$^~[]')q
vmap /
nnoremap . .n

nnoremap :help =expand("")
vnoremap y:help "
nnoremap :e#
nnoremap :q
nnoremap :e!
""{{{single-line comment behavior
"nnoremap I#j
"nnoremap ^:,s/\v^(\s*)#\s*/\1/en
autocmd BufWinEnter,BufNewFile * nnoremap I#j
autocmd BufWinEnter,BufNewFile *.c nnoremap I//j
autocmd BufWinEnter,BufNewFile *.cpp nnoremap I//j
autocmd BufWinEnter,BufNewFile *.v nnoremap I//j
autocmd BufWinEnter,BufNewFile *.sv* nnoremap I//j
autocmd BufWinEnter,BufNewFile *.*vim nnoremap I"j
autocmd BufWinEnter,BufNewFile .*vim* nnoremap I"j
autocmd BufWinEnter,BufNewFile * nnoremap ^:,s/\v(^\s*)@\<=#\s*//en
autocmd BufWinEnter,BufNewFile *.c nnoremap ^:,s/\v(^\s*)@\<=(\/\/)\s*//en
autocmd BufWinEnter,BufNewFile *.cpp nnoremap ^:,s/\v(^\s*)@\<=(\/\/)\s*//en
autocmd BufWinEnter,BufNewFile *.v nnoremap ^:,s/\v(^\s*)@\<=(\/\/)\s*//en
autocmd BufWinEnter,BufNewFile *.sv* nnoremap ^:,s/\v(^\s*)@\<=(\/\/)\s*//en
autocmd BufWinEnter,BufNewFile *.*vim nnoremap ^:,s/\v(^\s*)@\<="\s*//en
autocmd BufWinEnter,BufNewFile .*vim* nnoremap ^:,s/\v(^\s*)@\<="\s*//en
"nnoremap I//j
"nnoremap ^:,s/\v^(\s*)\/\//\1/n
"nnoremap I#j
"nnoremap ^:,s/\v^(\s*)#/\1/n
"}}}single-line comment behavior
"" avoid annoying K by mistake
nnoremap K :K
nnoremap @a
nnoremap :lt ""quick return to previous tag stack
vnoremap [ xi[]"
vnoremap { xi{}"
vnoremap ( xi()"
vnoremap " xi"""
vnoremap : :
vnoremap / y/=escape(@", '\\/.*$^~[]')
vnoremap y/=escape(@", '\\/.*$^~[]')
vnoremap y:s/=escape(@", '\\/.*$^~[]')//
""vnoremap y:promptfind
vnoremap >gv
vnoremap inoremap ( ()
inoremap { {}
inoremap [ []
autocmd BufEnter * :if &ft != 'vim' | inoremap " ""| endif
nnoremap sv :set syntax=verilog_systemverilog
if has("win32")
nnoremap ss :source $VIMRUNTIME\..\_vimrc
else
nnoremap ss :source ~/.vimrc
endif
nnoremap v :set pastemui+mv'uV'v=:set nopaste
vnoremap tn y:tabnew =escape(@", '\\/.*$^~[]')
vnoremap te y:tabedit =escape(@", '\\/.*$^~[]')
"noremap
"" allow me to use double to give up
noremap

" Fast diff
" DON'T remove the tailing space, as it is used as deliminater
nnoremap :vertical diffsplit
nnoremap :diffupdate
if version >= 700
set diffopt+=vertical
endif
nnoremap :diffget]c
nnoremap :diffput]c
" Fast grep
nnoremap g :lv /=expand("")/ %:lw
vnoremap g :lv /=GetVisualSelection()/ %:lw
""}}} map

"--------------------------------------for plugins-------------------------------
"-------------------------------------- for markbrowser
"markbrowser setting
nnoremap m :MarksBrowser
"-------------------------------------- lookupfile setting
"{{{lookupfile
let g:LookupFile_MinPatLength = 2
let g:LookupFile_PreserveLastPattern = 0
let g:LookupFile_PreservePatternHistory = 0
let g:LookupFile_AlwaysAcceptFirst = 1
let g:LookupFile_AllowNewFiles = 0
if filereadable("./filenametags")
let g:LookupFile_TagExpr = '"./filenametags"'
endif
nnoremap lk LookupFile
nnoremap ll :LUBufs
nnoremap lw :LUWalk
" lookup file with ignore case
fun! LookupFile_IgnoreCaseFunc(pattern)
let _tags = &tags
try
let &tags = eval(g:LookupFile_TagExpr)
let newpattern = '\c' . a:pattern
let tags = taglist(newpattern)
catch
echohl ErrorMsg | echo "Exception: " . v:exception | echohl NONE
return ""
finally
let &tags = _tags
endtry
" Show the matches for what is typed so far.
let files = map(tags, 'v:val["filename"]')
return files
endfun
let g:LookupFile_LookupFunc = 'LookupFile_IgnoreCaseFunc'
"}}}lookupfile
"----------------------------------------------- for minibufexpl.vim
"" {{{minibuffer
""let loaded_minibufexplorer = 1 " *** Disable minibuffer plugin
""let g:miniBufExplForceSyntaxEnable = 1 " force syntax on
"let g:miniBufExplVSplit = 25
"let winManagerWindowLayout = 'FileExplorer|TagList' "set 'TagList' in the 'winManagerWindowLayout'
let g:miniBufExplMapWindowNavArrow = 1
let g:miniBufExplMapCTabSwitchBufs = 1
let g:miniBufExplorerMoreThanOne = 2 " Display when more than 2 buffers
let g:miniBufExplSplitToEdge = 1 " Always at top
let g:miniBufExplMaxSize = 3 " The max height is 3 lines
let g:miniBufExplMapWindowNavVim = 1 " map CTRL-[hjkl]
let g:miniBufExplUseSingleClick = 1 " select by single click
let g:miniBufExplModSelTarget = 1 " Dont change to unmodified buffer
let g:miniBufExplSplitBelow = 0
autocmd BufRead,BufNew :call UMiniBufExplorer
""}}}minibuffer

"----------------------------------------------- for bufexplorer.vim
" Let to show buf explorer(bufexplorer plugin)
nmap ,be
"" is reserved for Visual Mark (same as UltraEdit)
"----------------------------------------------- for mru.vim
let MRU_Max_Entries = 100
nnoremap <> :MRU
"----------------------------------------------- for showmarks.vim ""disabled
""let g:showmarks_include="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"


"""svtags
if $USER == "lfchen"
set tags=/proj/lynley/ws/lfchen/mgnmFlow/interconnect/tags,/proj/lynley/ws/lfchen/mgnmFlow/bio/tags
else
set tags=/proj/lynley/ws/lfchen/mgnmFlow/interconnect/tags,/Please/Specify/Your/Own/tags
endif
"""matchit
au BufReadPost * let b:match_ignorecase=0
au BufReadPost * let b:match_words=
\ '^\s*\:^\s*\,' .
\ '^\s*\:^\s*\,' .
\ '^\s*\:^\s*\,' .
\ '\:^\s*\,' .
\ '^\s*\\|\\|\:^\s*\,' .
\ '^\s*\:^\s*\,' .
\ '^\s*\:\\|\\|\:\,' .
\ '^\s*\:\,' .
\ '^\s*\:^\s*\,' .
\ '^\s*`ifdef\>\|^\s*`ifndef\>:^\s*`else\>:^\s*`endif\>,' .
\ '^\s*\:^\s*\,' .
\ '^\s*\:\,' .
\ '^\s*\:\,' .
\ '^\s*\:\,' .
\ '^\s*\:\,' .
\ '^\s*\:^\s*\,' .
\ '^\s*\:^\s*\\|^\s*\|^\s*\,' .
\ '^\s*\:^\s*\,'.
\ '^\s*\:^\s*\'
au BufReadPost *.xml let b:match_words=
\ '^\s*\:^\s*\,'.
\ '<\(\w\+\):,'.
\ '<:>'
"" remember where I was when reopening a file
au BufReadPost * if line("'\"") > 0
au BufReadPost * if line("'\"") <= line("$")
au BufReadPost * exe("norm '\"")
au BufReadPost * else
au BufReadPost * exe "norm $"
au BufReadPost * endif
au BufReadPost * endif

"{{{--------------------------------------for autocmd and filetype------------------
"filetype plugin on
filetype indent on
"" enable file type detection
filetype on
"" backup last search pattern for each window
"au WinEnter * :if exists("w:blsp") && w:blsp != '' | let @/=w:blsp | endif
"au WinLeave * :let w:blsp=@/

fun! StatusLineGetPath() "{{{
let p = expand('%:.:h') "relative to current path, and head path only
let p = substitute(p,'\','/','g')
let p = substitute(p, '^\V' . $HOME, '~', '')
if len(p) > g:statusline_max_path
let p = simplify(p)
let p = pathshorten(p)
endif
return p
endfun ""}}}StatusLineGetPath

fun! StatusLineRealSyn() "{{{
let synId = synID(line('.'),col('.'),1)
let realSynId = synIDtrans(synId)
if synId == realSynId
return 'Normal'
else
return synIDattr( realSynId, 'name' )
endif
endfun ""}}}StatusLineRealSyn

fun! LastModified() "{{{
if &modified
let save_cursor = getpos(".")
let n = min([20, line("$")])
exe '1,' . n . 's#^\(.\{,10\}Last modified\s*:\).*#\1' . strftime('%a %b %d, %Y %I:%M%p') . '#e'
call setpos('.', save_cursor)
endif
endfun ""}}}LastModified
autocmd BufWritePre *.sv* call LastModified()
iab A_date =strftime("%c")

fun! SetHead_scr() "{{{
call setline(1,"#!/usr/bin/env ".&filetype)
call append(line("."), "\#-------------------------------------------------------------------------")
call append(line(".")+1, "\#File name : ".expand("%"))
call append(line(".")+2, "\#Author : ".$USER ." (Full Name please)")
call append(line(".")+3, "\#Created : ".strftime("%c"))
call append(line(".")+4, "\#Description : ")
call append(line(".")+5, "\# : ")
call append(line(".")+6, "\#Notes : ")
call append(line(".")+7, "\#-------------------------------------------------------------------------")
call append(line(".")+8, "\#Copyright 2010 (c)")
call append(line(".")+9, "\#-------------------------------------------------------------------------")
call append(line(".")+10,"")
endfun ""}}}SetHead_scr
fun! SetHead_sv() "{{{
call setline(1,"\//-------------------------------------------------------------------------")
call append(line("."), "\//File name : ".expand("%"))
call append(line(".")+1, "\//Author : ".$USER ." (Full Name please)")
call append(line(".")+2, "\//Created : ".strftime("%c"))
call append(line(".")+3, "\//Description : ")
call append(line(".")+4, "\// : ")
call append(line(".")+5, "\//Notes : ")
call append(line(".")+6, "\//-------------------------------------------------------------------------")
call append(line(".")+7, "\//Copyright 2010 (c)")
call append(line(".")+8, "\//-------------------------------------------------------------------------")
call append(line(".")+9, "")
endfun ""}}}SetHead_sv
fun! s:GetVisualSelection()
let save_a = @a
silent normal! gv"ay
let v = @a
let @a = save_a
let var = escape(v, '\\/.$*')
return var
endfun
func! DeleteTrailingWS()
exe "normal mz"
%s/\s\+$//ge
exe "normal `z"
endfunc
autocmd BufWrite *.py :call DeleteTrailingWS()
autocmd BufWrite *.pl :call DeleteTrailingWS()
autocmd BufWrite *.sv* :call DeleteTrailingWS()
autocmd BufNewFile *.[c|sv]* exec ":call SetHead_sv()"
"autocmd BufNewFile *.sv 0r $mrepo/skeleton.sv
autocmd BufNewFile *.pl exec ":call SetHead_scr()"
autocmd BufNewFile *.py exec ":call SetHead_scr()"
autocmd FileType python set omnifunc=pythoncomplete#Complete
autocmd FileType make setlocal tabstop=4 softtabstop=4 shiftwidth=4 noexpandtab
autocmd FileType python setlocal tabstop=4 softtabstop=4 shiftwidth=4 expandtab
autocmd FileType * :if &ft != 'python' && &ft != 'make' | set tabstop=2 softtabstop=2 shiftwidth=2 expandtab | endif
"autocmd FileType python set foldmethod=syntax ""not working
autocmd FileType text set spell spelllang=en_us
autocmd BufRead,BufNewFile *.txt :if &ft != 'help' | setfiletype text | endif
" make tab characters and trailing whitespace obvious
autocmd FileType * :if &ft != 'help' | 2match Error /\t\+ \+\| \+\t\+\|\s\+$/ | endif

""}}} autocmd

No comments: