爲了實現相似SourceInsight功能,經過VIM+Ctags+Cscope+Taglist+Source Explore +NERD Tree實現.css
一, 安裝插件html
1)安裝Ctags 和Cscopelinux
Ubuntu下能夠直接經過命令安裝:sql
sudo apt-get install ctags cscope
注:cscope與ctags功能相似,但能補充Ctags的不足,兩者結合便能兼具ctags的便利,雙能用cscope補充ctags的侷限,算得上是Linux內核代碼分析的強大工具.數據庫
2)安裝taglist :vim
經過向.vimrc中添加:函數
Bundle 'taglist.vim'
Bundle "scrooloose/nerdtree"
Bundle "wesleyche/SrcExpl"
Bundle "majutsushi/tagbar"
再執行:BundleInstall命令便可自動安裝.工具
3)post
二,配置和使用插件ui
在Linux內核已經自帶ctags和cscope的標籤數據庫的生成腳本,在內核源代碼目錄下經過命令可生成相應的數據庫文件:
make ctags make cscope
注:前者,生成一個92M的tags文件,後者會生成cscope.files(分析文件的目錄)和其它文件數據庫.
配置ctags和cscope的數據庫與VIM聯動:
""" ctags database path """"""" set tags=/home/magc/workspace/linux-2.6.32.67/tags """ cscope database path """"""" set csprg=/usr/bin/cscope "whereis cscope set csto=0 "cscope DB search first set cst "cscope db tag DB search set nocsverb "verbose off "cs db path cs add /home/magc/workspace/linux-2.6.32.67/cscope.out set csverb "verbos off
taglist插件配置:
""""""""tag list setting """""""" filetype on nmap <F7> :TlistToggle<CR> "F7 Key = Tag list Toggling let Tlist_Ctags_Cmd = "/usr/bin/ctags" " whereis ctags let Tlist_Inc_WinWidth = 0 "window width change off" let Tlist_Exit_OnlyWindow = 0 let Tlist_Auto_Open = 0 "VIM打開時 let Tlist_Use_Right_Window = 1
Source Explorer 插件配置:
""""""" Source Explorer Setting """""" nmap <F4> :SrcExplToggle<CR> "control+h進入左邊的窗口 nmap <C-H> <C-W>h "control+j進入下邊的窗口 nmap <C-J> <C-W>j "control+k進入上邊的窗口 nmap <C-K> <C-W>k "control+l進入右邊的窗口 nmap <C-L> <C-W>l let g:Srcexpl_winHeight = 8 " // Set 100 ms for refreshing the Source Explorer let g:SrcExpl_refreshTime = 100 " // Set "Enter" key to jump into the exact definition context let g:SrcExpl_jumpKey = "<ENTER>" " // Set "Space" key for back the definition context let g:SrcExpl_gobackKey = "<SPACE>" let g:SrcExpl_isUpdateTags = 0
NERD Tree插件配置:
""""" NERD Tree Setting """"""""" let NERDTreeWinPos="left" nnoremap <F2> :NERDTreeToggle<CR>
注:上面設置中包含的快捷鍵有:
三,代碼瀏覽方法
相似SourceInsight的用法,只不過這裏有些窗口須要手動打開,經過F2,F4,F7打開如上圖的,先在左側的NERD文件樹中找到你要查看的文件,中間大窗口是源碼窗口,當光標在某變量或函數名上時,下面就會顯示它的定義,右側是當前文件的標籤(變量,函數名等)
注:這裏標籤的來源是cscope和ctags兩個數據庫,有關Cscope的詳細命令使用方法可參考:http://blog.csdn.net/dengxiayehu/article/details/6330200
附加1 Cscope搜索跳轉技巧:(參考:http://blog.chinaunix.net/uid-24774106-id-3556337.html)
nmap <leader>sa :cs add cscope.out<cr> nmap <leader>ss :cs find s <C-R>=expand("")<cr><cr> nmap <leader>sg :cs find g <C-R>=expand("")<cr><cr> nmap <leader>sc :cs find c <C-R>=expand("")<cr><cr> nmap <leader>st :cs find t <C-R>=expand("")<cr><cr> nmap <leader>se :cs find e <C-R>=expand("")<cr><cr> nmap <leader>sf :cs find f <C-R>=expand("")<cr><cr> nmap <leader>si :cs find i <C-R>=expand("")<cr><cr> nmap <leader>sd :cs find d <C-R>=expand("")<cr><cr>