經(jīng)過3天的煎熬,找各種資料終于弄了個(gè)基本的符合自己vim配置。 這篇文章以后會(huì)不定時(shí)更新。 用到的插件: - a.vim
- bufexplorer.vim
- color_sample_pack.vim
- csExplorer.vim
- DoxygenToolkit.vim
- genutils.vim
- list
- lookupfile.vim
- mark.vim
- minibufexpl.vim
- NERD_commenter.vim
- NERD_tree.vim
- project.vim
- ShowFunc.vim
- taglist.vim
- winfileexplorer.vim
- winmanager.vim
- wintagexplorer.vim
vimrc文件: - "display the cursor
- "set ruler
- set nocp
- filetype plugin on
-
- " detect the filetype
- " this sentence eq filetype on, filetype plugin on, filetype indent on
- filetype plugin indent on
- set nocompatible
-
- set foldmethod=syntax
-
- "set color display
- set t_Co=256
-
-
- "Set mapleader
- "when use just in normal mode type ,ee
- let mapleader = ","
-
- "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
-
- """"""""""""""""""""""""""""
- " MiniBufferExplorer "
- """"""""""""""""""""""""""""
- let g:miniBufExplMapWindowNavVim=1
- let g:miniBufExplMapWindowNavArrows=1
- let g:miniBufExplMapCTabSwitchBufs=1
- "let g:miniBufExplModSelTarget=1
-
-
- "進(jìn)行Taglist的設(shè)置
- "TlistUpdate可以更新tags
- map <F3> :silent! Tlist<CR>
- "按下F3就可以呼出了
- let Tlist_Ctags_Cmd='/usr/bin/ctags'
- "因?yàn)槲覀兎旁诃h(huán)境變量里,所以可以直接執(zhí)行
- let Tlist_Use_Right_Window=1
- "讓窗口顯示在右邊,0的話就是顯示在左邊
- let Tlist_Show_One_File=1
- "讓taglist可以同時(shí)展示多個(gè)文件的函數(shù)列表
- let Tlist_File_Fold_Auto_Close=1
- "非當(dāng)前文件,函數(shù)列表折疊隱藏
- let Tlist_Exit_OnlyWindow=1
- "當(dāng)taglist是最后一個(gè)分割窗口時(shí),自動(dòng)推出vim
- "是否一直處理tags.1:處理;0:不處理
- let Tlist_Process_File_Always=0
- "不是一直實(shí)時(shí)更新tags,因?yàn)闆]有必要
- let Tlist_Inc_Winwidth=0
-
-
- "設(shè)置字體
- "set guifont=DejaVu\ Sans\ Mono\ 10
- set guifont=Consolas\ 11
- " 開啟語法高亮
- syntax enable
- syntax on
- "設(shè)置了在窗口右側(cè)何處開始換行沒有\(zhòng)n符號(hào),textwidth有\(zhòng)n
- set wrapmargin=10
-
- "在代碼使用4個(gè)空格代替TAB符
- autocmd FileType c,cpp,py set shiftwidth=4 | set expandtab
-
- "zzg added
- "set statusline=%F%m%r%h%w\ [FORMAT=%{&ff}]\ [TYPE=%Y]\ [ASCII=\%03.3b]\ [HEX=\%02.2B]\ [POS=%04l,%04v][%p%%]\ [LEN=%L]
- "set laststatus=2
- "imap <C-s> <ESC>:w<cr>a
-
- set shiftwidth=4
- "set indent length
-
- set expandtab
- " set use a series of backspaces to replace tab
-
- set tabstop=4
- " set when press a tab how many backspaces will skip
-
- "關(guān)閉vi兼容模式
- "set nocp
-
- " 自動(dòng)切換目錄
- set autochdir
- " 打開行號(hào)顯示
- set nu
- " 設(shè)置文字編碼自動(dòng)識(shí)別
- set fencs=utf-8,cp936
- " 使用鼠標(biāo)
- set mouse=a
- " 設(shè)置高亮搜索
- set hlsearch
- " 設(shè)置代碼折疊
- "set fdm=indent
- "set foldmethod=syntax
- "autocmd FileType c,cpp setl fdm=syntax | setl fen
- " 輸入字符串就顯示匹配點(diǎn)
- set incsearch
- " 輸入的命令顯示出來,看的清楚些。
- set showcmd
- " 選擇配色方案
- "hi Nomal ctermfg=Grey ctermbg=Black
- colorscheme darkburn
- "colorscheme darkblue
- "colorscheme morning
-
- """"""""""""""""""""""""""""""
- " 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=30 " Split width
- "let g:bufExplorerUseCurrentWindow=1 " Open in new window.
- "autocmd BufWinEnter \[Buf\ List\] setl nonumber
-
- "打開當(dāng)前目錄文件列表
- """"""""""""""""""""""""""""""
- " netrw setting
- """"""""""""""""""""""""""""""
- let g:netrw_winsize = 30
- nmap <silent> fe :Sexplore!<cr>
-
-
- let g:LookupFile_TagExpr = '"./filenametags"'
-
-
-
- """""""""""""""""""""""""""""
- " WinManager setting
- """""""""""""""""""""""""""""
- let g:winManagerWindowLayout = "FileExplorer|TagList"
- let g:winManagerWidth = 30
- let g:defaultExplorer = 0
- nmap <C-W><C-F> :FirstExplorerWindow<cr>
- nmap <C-W><C-B> :BottomExplorerWindow<cr>
- nmap <silent> wm :WMToggle<cr>
-
- """"""""""""""""""""""""""""""
- " lookupfile setting
- """"""""""""""""""""""""""""""
- let g:LookupFile_MinPatLength = 2 "最少輸入2個(gè)字符才開始查找
- let g:LookupFile_PreserveLastPattern = 0 "不保存上次查找的字符串
- let g:LookupFile_PreservePatternHistory = 1 "保存查找歷史
- let g:LookupFile_AlwaysAcceptFirst = 1 "回車打開第一個(gè)匹配項(xiàng)目
- let g:LookupFile_AllowNewFiles = 0 "不允許創(chuàng)建不存在的文件
- if filereadable("./filenametags") "設(shè)置tag文件的名字
- let g:LookupFile_TagExpr = '"./filenametags"'
- endif
- "映射LookupFile為,lk
- nmap <silent> <leader>lk :LUTags<cr>
- "映射LUBufs為,ll
- nmap <silent> <leader>ll :LUBufs<cr>
- "映射LUWalk為,lw
- nmap <silent> <leader>lw :LUWalk<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'
-
-
- """"""""""""""""""""""""""""""
- " mark setting
- """"""""""""""""""""""""""""""
- nmap <silent> <leader>hl <Plug>MarkSet
- vmap <silent> <leader>hl <Plug>MarkSet
- nmap <silent> <leader>hh <Plug>MarkClear
- vmap <silent> <leader>hh <Plug>MarkClear
- nmap <silent> <leader>hr <Plug>MarkRegex
- vmap <silent> <leader>hr <Plug>MarkRegex
-
- "Quickfix hotkey
- autocmd FileType c,cpp map <buffer> <leader><space> :w<cr>:make<cr>
- nmap <leader>cn :cn<cr>
- nmap <leader>cp :cp<cr>
- nmap <leader>cw :cw 10<cr>
-
- "在當(dāng)前文件中快速查找光標(biāo)下的單詞:
- nmap <leader>lv :lv /<c-r>=expand("<cword>")<cr>/ %<cr>:lw<cr>
-
-
- map <F12> :call Do_CsTag()<CR>
- nmap <C-@>s :cs find s <C-R>=expand("<cword>")<CR><CR>:copen<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>:copen<CR>
- nmap <C-@>t :cs find t <C-R>=expand("<cword>")<CR><CR>:copen<CR>
- nmap <C-@>e :cs find e <C-R>=expand("<cword>")<CR><CR>:copen<CR>
- nmap <C-@>f :cs find f <C-R>=expand("<cfile>")<CR><CR>:copen<CR>
- nmap <C-@>i :cs find i ^<C-R>=expand("<cfile>")<CR>$<CR>:copen<CR>
- nmap <C-@>d :cs find d <C-R>=expand("<cword>")<CR><CR>:copen<CR>
- function Do_CsTag()
- let dir = getcwd()
- if filereadable("tags")
- if(g:iswindows==1)
- let tagsdeleted=delete(dir."\\"."tags")
- else
- let tagsdeleted=delete("./"."tags")
- endif
- if(tagsdeleted!=0)
- echohl WarningMsg | echo "Fail to do tags! I cannot delete the tags" | echohl None
- return
- endif
- endif
- if has("cscope")
- silent! execute "cs kill -1"
- endif
- if filereadable("cscope.files")
- if(g:iswindows==1)
- let csfilesdeleted=delete(dir."\\"."cscope.files")
- else
- let csfilesdeleted=delete("./"."cscope.files")
- endif
- if(csfilesdeleted!=0)
- echohl WarningMsg | echo "Fail to do cscope! I cannot delete the cscope.files" | echohl None
- return
- endif
- endif
- if filereadable("cscope.out")
- if(g:iswindows==1)
- let csoutdeleted=delete(dir."\\"."cscope.out")
- else
- let csoutdeleted=delete("./"."cscope.out")
- endif
- if(csoutdeleted!=0)
- echohl WarningMsg | echo "Fail to do cscope! I cannot delete the cscope.out" | echohl None
- return
- endif
- endif
- if(executable('ctags'))
- "silent! execute "!ctags -R --c-types=+p --fields=+S *"
- silent! execute "!ctags -R --c++-kinds=+p --fields=+iaS --extra=+q ."
- endif
- if(executable('cscope') && has("cscope") )
- if(g:iswindows!=1)
- silent! execute "!find . -name '*.h' -o -name '*.c' -o -name '*.cpp' -o -name '*.java' -o -name '*.cs' > cscope.files"
- else
- silent! execute "!dir /s/b *.c,*.cpp,*.h,*.java,*.cs >> cscope.files"
- endif
- silent! execute "!cscope -b"
- execute "normal :"
- if filereadable("cscope.out")
- execute "cs add cscope.out"
- endif
- endif
- endfunction
-
-
-
-
- " OmniCppComplete
- let OmniCpp_NamespaceSearch = 1
- let OmniCpp_GlobalScopeSearch = 1
- let OmniCpp_ShowAccess = 1
- let OmniCpp_ShowPrototypeInAbbr = 1 " show function parameters
- let OmniCpp_MayCompleteDot = 1 " autocomplete after .
- let OmniCpp_MayCompleteArrow = 1 " autocomplete after ->
- let OmniCpp_MayCompleteScope = 1 " autocomplete after ::
- let OmniCpp_DefaultNamespaces = ["std", "_GLIBCXX_STD"]
- " automatically open and close the popup menu / preview window
- autocmd CursorMovedI,InsertLeave * if pumvisible() == 0|silent! pclose|endif
-
-
-
- " set something for ominicomplete
- set completeopt=longest,menu
-
- "對(duì)NERD_commenter的設(shè)置
- let NERDShutUp=1
-
- map fg :Dox<cr>
- let g:DoxygenToolkit_authorName="zzg"
- let g:DoxygenToolkit_licenseTag="My own license\<enter>"
- let g:DoxygenToolkit_undocTag="DOXIGEN_SKIP_BLOCK"
- let g:DoxygenToolkit_briefTag_pre = "@brief\t"
- let g:DoxygenToolkit_paramTag_pre = "@param\t"
- let g:DoxygenToolkit_returnTag = "@return\t"
- let g:DoxygenToolkit_briefTag_funcName = "no"
- let g:DoxygenToolkit_maxFunctionProtoLines = 30
-
-
-
- " mapping omini
- inoremap <expr> <CR> pumvisible()?"\<C-Y>":"\<CR>"
- inoremap <expr> <C-J> pumvisible()?"\<PageDown>\<C-N>\<C-P>":"\<C-X><C-O>"
- inoremap <expr> <C-K> pumvisible()?"\<PageUp>\<C-P>\<C-N>":"\<C-K>"
- inoremap <expr> <C-U> pumvisible()?"\<C-E>":"\<C-U>"
-
-
- set tags+=~/.vim/stl_tags
-
- "set paste if set this the omnicomplete will not work
- "remember to the last position you edit zzg
- if has("autocmd")
- autocmd BufRead *.txt set tw=78
- autocmd BufReadPost *
- \ if line("'\"") > 0 && line ("'\"") <= line("$") |
- \ exe "normal g'\"" |
- \ endif
- endif
總結(jié)一下安裝過程中遇到的問題: 安裝ctags由于以前安裝過emacs,所以有了emacs的ctags,我誤以為是exburant ctags已經(jīng)安裝了,結(jié)果錯(cuò)了很長(zhǎng)時(shí)間,要安裝Exburant ctags,也就是正常情況下的ctags。 安裝cscope時(shí)make錯(cuò)誤,就沒安,繼續(xù)往下,但是cpp的自動(dòng)補(bǔ)全不好使。后來查到cscope缺少的相關(guān)軟件有: bison , flex lib curses-dev 什么的 用 apt-cache search keywords 就能找到了.然后再安裝對(duì)應(yīng)的包就行了。 最后設(shè)置vim下用256色,并用了一個(gè)非常好看的顏色主題:darkburn.vim 有兩個(gè)網(wǎng)站關(guān)于vim講的非常好: http://www./ http:///blog/ 很敬佩這位大牛??! 下載插件的官網(wǎng)是:搜一下想找的插件立馬就會(huì)出來,官網(wǎng)很強(qiáng)大。 http://www./scripts/
|