我刚刚在我的Vim(或者更确切地说是gVim)中安装了Ctags(以帮助c++开发),并希望找到您最喜欢的命令,宏,快捷方式,提示……

分享你最好的武器库。对于Vim开发中的c++,您还推荐哪些Vim附加组件?

编辑你还会用什么附加组件来配合Ctags?

你用什么版本的gVim和标签?有区别吗?

你如何提高你的编程经验,无论是大项目还是小项目?


当前回答

我调整了上面的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()

其他回答

上面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

我使用ALT-left和ALT-right从标签堆栈中弹出/推送。

" Alt-right/left to navigate forward/backward in the tags stack
map <M-Left> <C-T>
map <M-Right> <C-]>

如果使用hjkl进行移动,则可以映射<M-h>和<M-l>。

我在我的.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

我已经调整我的vim插件两年了,以支持足够大的c++项目。你可以看一下。

他们使用ctags和cscsopx。

http://www.vim.org/scripts/script.php?script_id=1638 http://www.vim.org/scripts/script.php?script_id=2507