我刚刚在我的Vim(或者更确切地说是gVim)中安装了Ctags(以帮助c++开发),并希望找到您最喜欢的命令,宏,快捷方式,提示……
分享你最好的武器库。对于Vim开发中的c++,您还推荐哪些Vim附加组件?
编辑你还会用什么附加组件来配合Ctags?
你用什么版本的gVim和标签?有区别吗?
你如何提高你的编程经验,无论是大项目还是小项目?
我刚刚在我的Vim(或者更确切地说是gVim)中安装了Ctags(以帮助c++开发),并希望找到您最喜欢的命令,宏,快捷方式,提示……
分享你最好的武器库。对于Vim开发中的c++,您还推荐哪些Vim附加组件?
编辑你还会用什么附加组件来配合Ctags?
你用什么版本的gVim和标签?有区别吗?
你如何提高你的编程经验,无论是大项目还是小项目?
当前回答
上面SetCscope()函数的另一个迭代。这将设置cscope预路径以获取匹配,而不位于“cscope. conf”所在的目录。”是:
function s:FindFile(file)
let curdir = getcwd()
let found = curdir
while !filereadable(a:file) && found != "/"
cd ..
let found = getcwd()
endwhile
execute "cd " . curdir
return found
endfunction
if has('cscope')
let $CSCOPE_DIR=s:FindFile("cscope.out")
let $CSCOPE_DB=$CSCOPE_DIR."/cscope.out"
if filereadable($CSCOPE_DB)
cscope add $CSCOPE_DB $CSCOPE_DIR
endif
command -nargs=0 Cscope !cscope -ub -R &
endif
其他回答
上面SetCscope()函数的另一个迭代。这将设置cscope预路径以获取匹配,而不位于“cscope. conf”所在的目录。”是:
function s:FindFile(file)
let curdir = getcwd()
let found = curdir
while !filereadable(a:file) && found != "/"
cd ..
let found = getcwd()
endwhile
execute "cd " . curdir
return found
endfunction
if has('cscope')
let $CSCOPE_DIR=s:FindFile("cscope.out")
let $CSCOPE_DB=$CSCOPE_DIR."/cscope.out"
if filereadable($CSCOPE_DB)
cscope add $CSCOPE_DB $CSCOPE_DIR
endif
command -nargs=0 Cscope !cscope -ub -R &
endif
我发现标签列表插件是必备的。它在一个单独的窗口中列出它所知道的所有标签(您已打开的文件),并使它非常容易导航较大的文件。
我主要在Python开发中使用它,但它只适合C/ c++。
另一个对C开发有用的插件是cscope 正如Ctags允许跳转到定义一样,Cscope也可以跳转到调用函数。
如果您的~/bin/目录中有cscope,请将以下内容添加到.vimrc中,并使用g^]转到调用函数(参见:help cscope)。
if has("cscope")
set csprg=~/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
endif
差点忘了……就像ctags一样,您必须生成(并定期更新)数据库。我使用以下脚本
select_files > cscope.files
ctags -L cscope.files
ctags -e -L cscope.files
cscope -ub -i cscope.files
其中'select_files'是另一个从Makefile中提取C文件和头文件列表的脚本。这样我只索引项目实际使用的文件。
我调整了上面的SetTags()搜索函数(应该用等价的set tags+=./tags;/代替),以适用于cscope。似乎有用!
"cscope file-searching alternative
function SetCscope()
let curdir = getcwd()
while !filereadable("cscope.out") && getcwd() != "/"
cd ..
endwhile
if filereadable("cscope.out")
execute "cs add " . getcwd() . "/cscope.out"
endif
execute "cd " . curdir
endfunction
call SetCscope()
我已经调整我的vim插件两年了,以支持足够大的c++项目。你可以看一下。
他们使用ctags和cscsopx。
http://www.vim.org/scripts/script.php?script_id=1638 http://www.vim.org/scripts/script.php?script_id=2507