下面这个.vimrc文件是根据公司里的一个前辈配置的,这里记录下,方便以后使用。它的功能,其实跟网上很多.vimrc配置的相比,还是小儿科。我记录下来,主要还是因为自己已经习惯了这个工作环境跟快捷键。
1.如果你是在ubuntu下面使用vim,.vimrc文件时放置在~目录下就可以了。如果你是在window下使用gvim,那么你可以把配置文件放到你的安装目录下,例如,我的就是在C:\Program Files (x86)\Vim下,文件名问_vimrc
"""""""""""""""""""""""""""""" "General """""""""""""""""""""""""""""" "Get out of VI's compatible mode.. set nocompatible set tags=./tags,./../tags,./../../tags,./../../../tags,./../../../../tags,./../../../../../tags,./../../../../../../tags,./../../../../../../../tags,./../../../../../../../../tags,./../../../../../../../../../tags,./../../../../../../../../../../tags,./../../../../../../../../../../../tags,./../../../../../../../../../../../../tags,./../../../../../../../../../../../../../tags,./../../../../../../../../../../../../../../tags "Have the mouse enabled all the time: "set tags "if getfsize("vimscript")>0 " source vimscript "endif set mouse= set path+=** set wildmenu set nu "set ignorecase smartcase "set incsearch " Set to auto read when a file is changed from the outside set autoread "Set mapleader let mapleader = "," let g:mapleader = "," "do not use autoload_cscope map let g:autocscope_menus = 0 "open the bufexplorer.vim "let g:bufexplorer_version = "7.4.6" "close the autoload_cscope.vim "let g:loaded_autoload_cscope = 1 "close the ninibufexplorer.vim let g:loaded_minibufexplorer = 1 "Enable syntax hl syntax enable "Highlight search things set hls set ignorecase set smartcase set encoding=utf-8 set ambiwidth=double "Set font to Monospace 11pt set guifont=Monospace\ 11 "set color "colorscheme darkblue "Hide menu bar & tool bar of GVim set guioptions-=m set guioptions-=T """""""""""""""""""""""""""""" "Indent """""""""""""""""""""""""""""" "Auto indent set ai "Smart indet set si "C-style indeting "set cindent "filetype plugin indent on "set nocp "if version >= 600 " filetype plugin indent on "endif """""""""""""""""""""""""""""" " netrw setting """""""""""""""""""""""""""""" let g:netrw_winsize = 40 nmap <silent> <leader>fe :Sexplore!<cr> """""""""""""""""""""""""""""" " BufExplorer """""""""""""""""""""""""""""" let g:bufExplorerDefaultHelp=0 " Do not show default help. let g:bufExplorerShowRelativePath=1 " Show relative paths. let g:bufExplorerSortBy='mru' " Sort by most recently used. let g:bufExplorerSplitRight=0 " Split left. let g:bufExplorerSplitVertical=1 " Split vertically. let g:bufExplorerSplitVertSize = 40 " Split width let g:bufExplorerUseCurrentWindow=1 " Open in new window. "let g:bufExplorerFindActive=0 " do not go to activity window nmap <silent> <leader>bf :buffer<cr> autocmd BufWinEnter \[Buf\ List\] setl nonumber """""""""""""""""""""""""""""" " winManager setting """""""""""""""""""""""""""""" let g:winManagerWindowLayout = "BufExplorer|TagList" let g:winManagerWidth = 40 let g:defaultExplorer = 0 "auto open winmanager let g:AutoOpenWinManager = 0 nmap <C-W><C-F> :FirstExplorerWindow<cr> nmap <C-W><C-B> :BottomExplorerWindow<cr> nmap <silent> <leader>d :WMToggle<cr> "only the explorer windows are the ones left, vim will quit let g:persistentBehaviour = 0 "auto close Winmanager "autocmd bufenter * if (winnr("$") == 2 && exists("b:NERDTreeType") &&b:NERDTreeType == "primary") | qa | endif set cindent set softtabstop=4 set expandtab set shiftwidth=4 """""""""""""""""""""""""""""" "Cscope """""""""""""""""""""""""""""" 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 nmap <leader>cs :cs find s <C-R>=expand("<cword>")<CR><CR> nmap <leader>cg :cs find g <C-R>=expand("<cword>")<CR><CR> nmap <leader>cc :cs find c <C-R>=expand("<cword>")<CR><CR> nmap <leader>ct :cs find t <C-R>=expand("<cword>")<CR><CR> nmap <leader>ce :cs find e <C-R>=expand("<cword>")<CR><CR> nmap <leader>cf :cs find f <C-R>=expand("<cfile>")<CR><CR> nmap <leader>ci :cs find i <C-R>=expand("<cfile>")<CR><CR> nmap <leader>cd :cs find d <C-R>=expand("<cword>")<CR><CR> """""""""""""""""""""""""""""" "Fast saving & quiting """""""""""""""""""""""""""""" nmap <silent> <leader>w :w!<cr> nmap <silent> <leader>q :q<cr> nmap <silent> <leader>qf :q!<cr> nmap <silent> <leader>wq :w!<cr>:qall<cr> nmap <silent> <leader>qq :qall<cr> """""""""""""""""""""""""""""" "Fast saving & loading session """""""""""""""""""""""""""""" nmap <silent> <leader>ms :mksession! ~/.vim/last.vim<cr> nmap <silent> <leader>ss :source ~/.vim/last.vim<cr> "Fast reloading of the .vimrc nmap <leader>s :w<cr>:source ~/.vimrc<cr> ""Fast editing of .vimrc nmap <leader>e :e! ~/.vimrc<cr> """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " Files and backups """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " "Turn backup off set nobackup set nowb set noswapfile """""""""""""""""""""""""""""" " Tag setting """""""""""""""""""""""""""""" nmap <cr> <C-]> nmap <F7> :ts <C-R>=expand("<cword>")<CR><CR> """""""""""""""""""""""""""""" " Tag list (ctags) """""""""""""""""""""""""""""" "we have winManager,so wo remove this "nmap <silent> <leader>d :TlistToggle<cr> nmap <C-h> <C-W>h nmap <C-j> <C-W>j nmap <C-k> <C-W>k nmap <C-l> <C-W>l let Tlist_Show_One_File = 1 let Tlist_Exit_OnlyWindow = 1 let Tlist_Sort_Type = "name" let Tlist_WinWidth = 40 """""""""""""""""""""""""""""" " "Enable folding, I find it very useful """""""""""""""""""""""""""""" "syn region myFold start="{" end="}" transparent fold "syn sync fromstart "set foldmethod=syntax set nofen set fdl=0 """""""""""""""""""""""""""""" "Auto complete """""""""""""""""""""""""""""" set complete-=i """"""""""""""""""""""""""""""" "lookupfile setting """""""""""""""""""""""""""""" let g:LookupFile_MinPatLength = 4 let g:LookupFile_PreserveLastPattern = 0 let g:LookupFile_PreservePatternHistory = 1 let g:LookupFile_AlwaysAcceptFirst = 1 let g:LookupFile_AllowNewFiles = 0 let g:LookupFile_EnableRemapCmd = 0 if filereadable("./filenametags") let g:LookupFile_TagExpr = '"./filenametags"' "elseif filereadable("././filenametags") " let g:LookupFile_TagExpr = '"././filenametags"' "elseif filereadable("./././filenametags") " let g:LookupFile_TagExpr = '"./././filenametags"' "elseif filereadable("././././filenametags") " let g:LookupFile_TagExpr = '"././././filenametags"' "elseif filereadable("./././././filenametags") " let g:LookupFile_TagExpr = '"./././././filenametags"' "elseif filereadable("././././././filenametags") " let g:LookupFile_TagExpr = '"././././././filenametags"' "elseif filereadable("./././././././filenametags") " let g:LookupFile_TagExpr = '"./././././././filenametags"' "elseif filereadable("././././././././filenametags") " let g:LookupFile_TagExpr = '"././././././././filenametags"' "elseif filereadable("./././././././././filenametags") " let g:LookupFile_TagExpr = '"./././././././././filenametags"' endif nmap <silent> <leader>lt :LUTags<cr> nmap <silent> <leader>lb :LUBufs<cr> nmap <silent> <leader>lw :LUWalk<cr> nmap <silent> <F2> :LUBufs<cr> nmap <silent> <F3> :exec "LUWalk" expand('%:p:h').'/'<cr> nmap <silent> <F4> :exec "LUTags" expand("<cword>")<cr> " lookup file with ignore case function! 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 endfunction let g:LookupFile_LookupFunc = 'LookupFile_IgnoreCaseFunc' """"""""""""""""""""""""""""""" "Tab setting """""""""""""""""""""""""""""" nmap <leader>ta :tab nmap <silent> <leader>te :tabe<cr> nmap <silent> <leader>ts :tab sp<cr> nmap <silent> <leader>tc :tabc<cr> nmap <silent> <leader>to :tabo<cr> nmap <silent> <leader>tn :tabn<cr> nmap <silent> <leader>tp :tabp<cr> nmap <silent> <leader>tr :tabr<cr> map <silent> <S-Tab> :tabp<cr> map <silent> <Tab> :tabn<cr> """""""""""""""""""""""""""""" " showmarks setting """"""""""""""""""""""""""""""" "Enable ShowMarks let showmarks_enable = 1 "Show which marks let showmarks_include = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" " Ignore help, quickfix, non-modifiable buffers let showmarks_ignore_type = "hqm" "Hilight lower & upper marks let showmarks_hlline_lower = 1 let showmarks_hlline_upper = 1 """"""""""""""""""""""""""""""" "quick fix """""""""""""""""""""""""""""" autocmd FileType c,cpp nmap <leader><space> :w!<cr>:make<cr> autocmd BufNewFile,BufRead *.java set formatprg=astyle """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " General Autocommands """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" "Edit current dir map <F6> :e %:p:h<cr> nmap <leader>m :marks<cr> nmap <leader>j :ju<cr> nmap <leader>/ ^i//<esc> map <silent> <F8> :%s/ / /g<cr> map <silent> <F9> :%s/\s\+$//g<cr> vmap <silent> <F9> :s/\s\+$//g<cr> nmap <leader>rg :%s/^\s\+//<cr>:%s/ .*$//<cr>:%s/^/#修正 {{issue_title(/<cr>:%s/$/)}}/<cr> map aa :s*^\s\+\\|^*\0//*<cr>:noh<cr> map au :s*\(^\s\+\\|^\)//*\1*<cr>:noh<cr> map as :%s/\(.*\) \(.*\) \(.*\)/\1 \3 \2/ nmap <leader>lg oandroid.util.Log.e("Kern", "");<esc>2hi """""""""""""""""""""""""""""""""""""""""""""""""""""""" " personal settings """""""""""""""""""""""""""""""""""""""""""""""""""""""" highlight WhitespaceEOL ctermbg=red guibg=red match WhitespaceEOL /\s\+$/ "used for add code or delete/update code "for java & C/C++ map <leader>fj o<ESC>0i/* HQ:<Esc>:read !git config --get user.name<CR>kJ<Del>$a on:<Esc>:read !date -R <CR><ESC>kJ$o<ESC>0i * modify the bugfix<CR><Esc>0a */<CR><Esc>0i// End of HQ:<Esc>:read !git config --get user.name<CR>kJ<Del>k vmap <leader>fj xO<Esc>0i/* HQ:<CR><Esc>k:read !git config --get user.name<CR>kJi<Del><Esc>$a on:<CR><Esc>k:read !date -R <CR><ESC>kJ$o<ESC>0i * modify the bugfix<Esc>gp<Esc>0a */<CR><Esc>0i// End of HQ:<Esc>:read !git config --get user.name<CR>kJJ<Del>k "for perl map <leader>fp o<ESC>0i# HQ:<Esc>:read !git config --get user.name<CR>kJ<Del>$a on:<Esc>:read !date -R <CR><ESC>kJ$o<ESC>0i# modify the bugfix<CR><CR><Esc>0i# End of HQ:<Esc>:read !git config --get user.name<CR>kJ<Del>k vmap <leader>fp xO<Esc>0i# HQ:<CR><Esc>k:read !git config --get user.name<CR>kJi<Del><Esc>$a on:<CR><Esc>k:read !date -R <CR><ESC>kJ$o<ESC>0i# modify the bugfix<CR><ESC>0i=begin<Esc>gp<Esc>0a=end<CR><Esc>0a=cut<CR><CR><Esc>0i# End of HQ:<Esc>:read !git config --get user.name<CR>kJJ<Del>k "for shell map <leader>fs o<ESC>0i# HQ:<Esc>:read !git config --get user.name<CR>kJ<Del>$a on:<Esc>:read !date -R <CR><ESC>kJ$o<ESC>0i# modify the bugfix<CR><CR><Esc>0i# End of HQ:<Esc>:read !git config --get user.name<CR>kJ<Del>k vmap <leader>fs xO<Esc>0i# HQ:<CR><Esc>k:read !git config --get user.name<CR>kJi<Del><Esc>$a on:<CR><Esc>k:read !date -R <CR><ESC>kJ$o<ESC>0i# modify the bugfix<CR><ESC>0i: INGORED UP TO << '--END-COMMENT--'<Esc>gp<Esc>0a--END-COMMENT--<CR><CR><Esc>0i# End of HQ:<Esc>:read !git config --get user.name<CR>kJJ<Del>k "for makefile map <leader>fm o<ESC>0i# HQ:<Esc>:read !git config --get user.name<CR>kJ<Del>$a on:<Esc>:read !date -R <CR><ESC>kJ$o<ESC>0i# modify the bugfix<CR><CR><Esc>0i# End of HQ:<Esc>:read !git config --get user.name<CR>kJ<Del>k vmap <leader>fm xO<Esc>0i# HQ:<CR><Esc>k:read !git config --get user.name<CR>kJi<Del><Esc>$a on:<CR><Esc>k:read !date -R <CR><ESC>kJ$o<ESC>0i# modify the bugfix<CR><ESC>0iifdef 0<Esc>gp<Esc>0aendif<CR><CR><Esc>0i# End of HQ:<Esc>:read !git config --get user.name<CR>kJJ<Del>k "for xml map <leader>fx o<ESC>0i<!-- HQ:<Esc>:read !git config --get user.name<CR>kJ<Del>$a on:<Esc>:read !date -R <CR><ESC>kJ$o<ESC>0imodify the bugfix<CR><Esc>0a--><CR><CR><Esc>0i<!-- End of HQ:<Esc>:read !git config --get user.name<CR>$a --><Esc>kJ<Del>k vmap <leader>fx xO<Esc>0i<!-- HQ:<CR><Esc>k:read !git config --get user.name<CR>kJi<Del><Esc>$a on:<CR><Esc>k:read !date -R <CR><ESC>kJ$o<ESC>0imodify the bugfix<Esc>gp<Esc>0a--><CR><CR><Esc>0i<!-- End of HQ:<Esc>:read !git config --get user.name<CR>$a --><Esc>kJJ<Del>k