我刚刚在我的Vim(或者更确切地说是gVim)中安装了Ctags(以帮助c++开发),并希望找到您最喜欢的命令,宏,快捷方式,提示……
分享你最好的武器库。对于Vim开发中的c++,您还推荐哪些Vim附加组件?
编辑你还会用什么附加组件来配合Ctags?
你用什么版本的gVim和标签?有区别吗?
你如何提高你的编程经验,无论是大项目还是小项目?
我刚刚在我的Vim(或者更确切地说是gVim)中安装了Ctags(以帮助c++开发),并希望找到您最喜欢的命令,宏,快捷方式,提示……
分享你最好的武器库。对于Vim开发中的c++,您还推荐哪些Vim附加组件?
编辑你还会用什么附加组件来配合Ctags?
你用什么版本的gVim和标签?有区别吗?
你如何提高你的编程经验,无论是大项目还是小项目?
当前回答
另一个对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文件和头文件列表的脚本。这样我只索引项目实际使用的文件。
其他回答
我在我的.gvimrc文件中放入了以下内容,当gvim启动时,它会从树的任何一点开始搜索标签文件:
function SetTags()
let curdir = getcwd()
while !filereadable("tags") && getcwd() != "/"
cd ..
endwhile
if filereadable("tags")
execute "set tags=" . getcwd() . "/tags"
endif
execute "cd " . curdir
endfunction
call SetTags()
然后,我定期在我的源代码树的顶部重新生成一个标签文件,脚本看起来像:
#!/bin/bash
find . -regex ".*\.\(c\|h\|hpp\|cc\|cpp\)" -print | ctags --totals --recurse --extra="+qf" --fields="+i" -L -
以上所有的……
Code_complete:函数参数完成、代码片段等等。
http://www.vim.org/scripts/script.php?script_id=1764
标记列表。vim:源代码浏览器(支持C/ c++, java, perl, python, tcl, sql, php等)
http://www.vim.org/scripts/script.php?script_id=273
同一名称的多个定义
<C-w>g<C-]>以拆分方式打开定义,但也可以执行:tjump,它可以进入定义,如果有几个定义,则为您提供一个定义列表供您选择。
另一个对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文件和头文件列表的脚本。这样我只索引项目实际使用的文件。
上面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