现在的位置: 首页 > 综合 > 正文

我的vim配置文件

2014年02月28日 ⁄ 综合 ⁄ 共 10805字 ⁄ 字号 评论关闭

用了vim也有几个月了,感觉实在是太棒了,在这里将我的vim配置,与大家共享一下;

if v:lang =~ "utf8$" || v:lang =~ "UTF-8$"
   set fileencodings=utf-8,latin1
endif

let mapleader = ","
let g:mapleader = ","

"platform func
fun! MySys()
    if has("win32")
        return "windows"
    else
        return "linux"
endif
endfun

"Fast edit vimrc
if MySys() == 'linux'
    "Fast reloading of the .vimrc
    map <silent> <leader>ss :source ~/.vimrc<cr>
    "Fast editing of .vimrc
    map <silent> <leader>ee :e! ~/.vimrc<cr>
    "When .vimrc is edited, reload it
    autocmd! bufwritepost .vimrc source ~/.vimrc
elseif MySys() == 'windows'
    " Set helplang
    set helplang=cn
    "Fast reloading of the _vimrc
    map <silent> <leader>ss :source ~/_vimrc<cr>
    "Fast editing of _vimrc
    map <silent> <leader>ee :e! ~/_vimrc<cr>
    "When _vimrc is edited, reload it
    autocmd! bufwritepost _vimrc source ~/_vimrc
endi

let &termencoding=&encoding
set fileencodings=utf-8,gbk,gb231,ucs-bom,cp936

set nocompatible    " Use Vim defaults (much better!)
set bs=indent,eol,start        " allow backspacing over everything in insert mode
"set ai            " always set autoindenting on
"set backup        " keep a backup file
set viminfo='20,\"50    " read/write a .viminfo file, don't store more
" than 50 lines of registers
set history=50        " keep 50 lines of command line history
set ruler        " show the cursor position all the time
set cursorline
set number
set tabstop=4
set softtabstop=4
set shiftwidth=4
set noexpandtab
set smarttab
set autoindent
set smartindent
set hid "buffer change without saving

"打开buffer 快捷, buffer号+<F4>
map <F4> <C-^>

" 快速保存 退出
nmap <leader>w :w!<cr>
nmap <leader>q :q<cr>
nmap <leader>wq :wq<cr>
nmap <leader>m :make<cr>
nmap <leader>i :make install<cr>
nmap <leader>ls :ls<cr>
nmap <leader>db %ma%d'a

"常用映射

"set cindent
set cmdheight=2
set incsearch
set showmatch
set ignorecase
colorscheme desert
set background=dark

"noremap <Leader>m mmHmt:%s/<C-V><C-M>//ge<cr>'tzt'm
let Tlist_Ctags_Cmd="/usr/bin/ctags"
let Tlist_Use_Right_Window=1
let Tlist_Show_One_File=1
let Tlist_Auto_Open=1
let Tlist_Inc_Winwidth=0
let Tlist_Exit_OnlyWindow=1
nmap <silent> <F8> :Tlist<cr>

" Only do this part when compiled with support for autocommands
if has("autocmd")
" In text files, always limit the width of text to 78 characters
autocmd BufRead *.txt set tw=78
" When editing a file, always jump to the last cursor position
autocmd BufReadPost *
\ if line("'\"") > 0 && line ("'\"") <= line("$") |
\   exe "normal! g'\"" |
\ endif
endif

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => winmanager 设置
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"let g:winManagerWindowLayout = "BufExplorer|TagList"
"let g:AutoOpenWinManager=1
"nmap <silent> <F8> :WMToggle<cr>

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => cscope 设置
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
if has("cscope")

""""""""""""" Standard cscope/vim boilerplate

" use both cscope and ctag for 'ctrl-]', ':ta', and 'vim -t'
set csprg=/usr/local/bin/cscope
set cscopetag

" check cscope for definition of a symbol before checking ctags: set to 1
" if you want the reverse search order.
set csto=0

" add any cscope database in current directory
if filereadable("cscope.out")
cs add cscope.out  
" else add the database pointed to by environment variable
elseif $CSCOPE_DB != ""
cs add $CSCOPE_DB
endif

" show msg when any other cscope db added
set cscopeverbose  

""""""""""""" My cscope/vim key mappings
"
" The following maps all invoke one of the following cscope search types:
"
"   's'   symbol: find all references to the token under cursor
"   'g'   global: find global definition(s) of the token under cursor
"   'c'   calls:  find all calls to the function name under cursor
"   't'   text:   find all instances of the text under cursor
"   'e'   egrep:  egrep search for the word under cursor
"   'f'   file:   open the filename under cursor
"   'i'   includes: find files that include the filename under cursor
"   'd'   called: find functions that function under cursor calls
"
" Below are three sets of the maps: one set that just jumps to your
" search result, one that splits the existing vim window horizontally and
" diplays your search result in the new window, and one that does the same
" thing, but does a vertical split instead (vim 6 only).
"
" I've used CTRL-\ and CTRL-@ as the starting keys for these maps, as it's
" unlikely that you need their default mappings (CTRL-\'s default use is
" as part of CTRL-\ CTRL-N typemap, which basically just does the same
" thing as hitting 'escape': CTRL-@ doesn't seem to have any default use).
" If you don't like using 'CTRL-@' or CTRL-\, , you can change some or all
" of these maps to use other keys.  One likely candidate is 'CTRL-_'
" (which also maps to CTRL-/, which is easier to type).  By default it is
" used to switch between Hebrew and English keyboard mode.
"
" All of the maps involving the <cfile> macro use '^<cfile>$': this is so
" that searches over '#include <time.h>" return only references to
" 'time.h', and not 'sys/time.h', etc. (by default cscope will return all
" files that contain 'time.h' as part of their name).

" To do the first type of search, hit 'CTRL-\', followed by one of the
" cscope search types above (s,g,c,t,e,f,i,d).  The result of your cscope
" search will be displayed in the current window.  You can use CTRL-T to
" go back to where you were before the search.  
"

nmap <C-\>s :cs find s <C-R>=expand("<cword>")<CR><CR>    
nmap <C-\>g :cs find g <C-R>=expand("<cword>")<CR><CR>    
nmap <C-\>c :cs find c <C-R>=expand("<cword>")<CR><CR>    
nmap <C-\>t :cs find t <C-R>=expand("<cword>")<CR><CR>    
nmap <C-\>e :cs find e <C-R>=expand("<cword>")<CR><CR>    
nmap <C-\>f :cs find f <C-R>=expand("<cfile>")<CR><CR>    
nmap <C-\>i :cs find i ^<C-R>=expand("<cfile>")<CR>$<CR>
nmap <C-\>d :cs find d <C-R>=expand("<cword>")<CR><CR>    

" Using 'CTRL-spacebar' (intepreted as CTRL-@ by vim) then a search type
" makes the vim window split horizontally, with search result displayed in
" the new window.
"
" (Note: earlier versions of vim may not have the :scs command, but it
" can be simulated roughly via:
"    nmap <C-@>s <C-W><C-S> :cs find s <C-R>=expand("<cword>")<CR><CR>    

nmap <C-@>s :scs find s <C-R>=expand("<cword>")<CR><CR>    
nmap <C-@>g :scs find g <C-R>=expand("<cword>")<CR><CR>    
nmap <C-@>c :scs find c <C-R>=expand("<cword>")<CR><CR>    
nmap <C-@>t :scs find t <C-R>=expand("<cword>")<CR><CR>    
nmap <C-@>e :scs find e <C-R>=expand("<cword>")<CR><CR>    
nmap <C-@>f :scs find f <C-R>=expand("<cfile>")<CR><CR>    
nmap <C-@>i :scs find i ^<C-R>=expand("<cfile>")<CR>$<CR>    
nmap <C-@>d :scs find d <C-R>=expand("<cword>")<CR><CR>    

" Hitting CTRL-space *twice* before the search type does a vertical
" split instead of a horizontal one (vim 6 and up only)
"
" (Note: you may wish to put a 'set splitright' in your .vimrc
" if you prefer the new window on the right instead of the left

nmap <C-@><C-@>s :vert scs find s <C-R>=expand("<cword>")<CR><CR>
nmap <C-@><C-@>g :vert scs find g <C-R>=expand("<cword>")<CR><CR>
nmap <C-@><C-@>c :vert scs find c <C-R>=expand("<cword>")<CR><CR>
nmap <C-@><C-@>t :vert scs find t <C-R>=expand("<cword>")<CR><CR>
nmap <C-@><C-@>e :vert scs find e <C-R>=expand("<cword>")<CR><CR>
nmap <C-@><C-@>f :vert scs find f <C-R>=expand("<cfile>")<CR><CR>    
nmap <C-@><C-@>i :vert scs find i ^<C-R>=expand("<cfile>")<CR>$<CR>    
nmap <C-@><C-@>d :vert scs find d <C-R>=expand("<cword>")<CR><CR>

""""""""""""" key map timeouts
"
" By default Vim will only wait 1 second for each keystroke in a mapping.
" You may find that too short with the above typemaps.  If so, you should
" either turn off mapping timeouts via 'notimeout'.
"
"set notimeout
"
" Or, you can keep timeouts, by uncommenting the timeoutlen line below,
" with your own personal favorite value (in milliseconds):
"
"set timeoutlen=4000
"
" Either way, since mapping timeout settings by default also set the
" timeouts for multicharacter 'keys codes' (like <F1>), you should also
" set ttimeout and ttimeoutlen: otherwise, you will experience strange
" delays as vim waits for a keystroke after you hit ESC (it will be
" waiting to see if the ESC is actually part of a key code like <F1>).
"
"set ttimeout
"
" personally, I find a tenth of a second to work well for key code
" timeouts. If you experience problems and have a slow terminal or network
" connection, set it higher.  If you don't set ttimeoutlen, the value for
" timeoutlent (default: 1000 = 1 second, which is sluggish) is used.
"
"set ttimeoutlen=100

endif

" Switch syntax highlighting on, when the terminal has colors
" Also switch on highlighting the last used search pattern.
if &t_Co > 2 || has("gui_running")
syntax on
set hlsearch
endif

if &term=="xterm"
set t_Co=8
set t_Sb=[4%dm
set t_Sf=[3%dm
endif
set fileencodings=utf-8,gb2312,gbk,gb18030
set termencoding=utf-8
set fileformats=unix,dos,mac
"^M
"noremap <Leader>m mmHmt:%s<C-V><cr>//ge<cr>'ztz'm
"set encoding=prc
set encoding=utf-8
set tags=./tags
set autochdir
"set cscopequickfix=s-,c-,d-,i-,t-,e-

let g:proj_window_width=20
let g:proj_window_increment=90
let g:proj_flags='i'
let g:proj_flags='s'
let g:proj_flags='m'
let g:proj_flags='t'
let g:proj_flags='L'
let g:proj_flags='S'
let g:proj_flags='V'
let g:proj_flags='i'

"窗口快速切换
nn <c-h> <c-w>h
nn <c-j> <c-w>j
nn <c-k> <c-w>k
nn <c-l> <c-w>l

" 用空格键来开关折叠
set foldenable
set foldmethod=manual
nnoremap <space> @=((foldclosed(line('.')) < 0) ? 'zc' : 'zo')<CR>

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => project 设置
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"nmap <silent> <F8> :Project <cr>

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => grep 设置
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
nnoremap <silent> <F3> :Grep -r<CR>

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => a 设置
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
nnoremap <silent> <F12> :A<CR>

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => NerdTree 设置
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"NERDTree plugin
let NERDTreeWinPos = "left" "where NERD tree window is placed on the screen

let NERDTreeWinSize = 20 "size of the NERD tree
nmap <F7> <ESC>:NERDTreeToggle<RETURN>" Open and close the NERD_tree.vim separatel
let g:AutoOpenNerdTree=1

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => minibuf 设置
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"let g:miniBufExplModSelTarget = 1
"let g:miniBufExplorerMoreThanOne = 0
"let g:miniBufExplModSelTarget = 0
"let g:miniBufExplUseSingleClick = 1
"let g:miniBufExplMapWindowNavVim = 1
"let g:miniBufExplVSplit = 25
"let g:miniBufExplSplitBelow=1
"
""WindowZ
"map <c-w><c-t> :WMToggle<cr>
"let g:bufExplorerSortBy = "name"
let g:miniBufExplMapWindowNavVim = 1
let g:miniBufExplMapWindowNavArrows = 1
let g:miniBufExplMapCTabSwitchBufs = 1
let g:miniBufExplModSelTarget = 1

""""""""""""""""""""""""""""""
" lookupfile setting
""""""""""""""""""""""""""""""
let g:LookupFile_MinPatLength = 2
let g:LookupFile_PreserveLastPattern = 0
let g:LookupFile_PreservePatternHistory = 1
let g:LookupFile_AlwaysAcceptFirst = 1
let g:LookupFile_AllowNewFiles = 0
if filereadable("./filenametags")
let g:LookupFile_TagExpr = '"./filenametags"'
endif
nmap <silent> <leader>lk :LUTags<cr>
nmap <silent> <leader>ll :LUBufs<cr>
nmap <silent> <leader>lw :LUWalk<cr>

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => NERD_commenter 设置
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"对NERD_commenter的设置
"let NERDShutUp=1
"支持单行和多行的选择,//格式
"map <c-m> ,c<space>

" update tags and cscope
nmap <F11> <Esc>:!ctags -R *<cr> :!find $(pwd) -name "*.c" -or -name "*.h" -or -name "*.cpp" > cscope.files<cr>:!cscope -b<cr>:cs kill cscope.out<cr>:cs add cscope.out<cr>

"{} () [] "" 补全
"inoremap ( ()<ESC>i
"inoremap ) <c-r>=ClosePair(')')<CR>
"inoremap { {}<ESC>i
"inoremap } <c-r>=ClosePair('}')<CR>
"inoremap [ []<ESC>i
"inoremap ] <c-r>=ClosePair(']')<CR>
""inoremap < <><ESC>i
""inoremap > <c-r>=ClosePair('>')<CR>
"
"function ClosePair(char)
"    if getline('.')[col('.') - 1] == a:char
"        return "\<Right>"
"    else
"        return a:char
"    endif
"endf

map <C-F10> :!ctags -R --c++-kinds=+p --fields=+iaS --extra=+q .<CR>

【上篇】
【下篇】

抱歉!评论已关闭.