为了实现类似SourceInsight功能,通过VIM+Ctags+Cscope+Taglist+Source Explore +NERD Tree实现.
一, 安装插件
1)安装Ctags 和Cscope
Ubuntu下可以直接通过命令安装:
sudo apt-get install ctags cscope
注:cscope与ctags功能类似,但能补充Ctags的不足,二者结合便能兼具ctags的便利,双能用cscope补充ctags的局限,算得上是Linux内核代码分析的强大工具.
2)安装taglist :
通过向.vimrc中添加:
Bundle ‘taglist.vim‘Bundle "scrooloose/nerdtree" Bundle "wesleyche/SrcExpl" Bundle "majutsushi/tagbar"
再执行:BundleInstall命令即可自动安装.
3)
二,配置和使用插件
在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 /home/magc/workspace/linux-2.6.32.67 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>
注:上面设置中包含的快捷键有:
- F7打开Taglist
- F4打开Source Explorer
- F2打开Nerd Tree
- control+h进入左边的窗口
- control+k进入上边的窗口
- control+j进入下边的窗口
- control+l进入右边的窗口
时间: 2024-10-18 11:13:36