我刚刚在我的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()

其他回答

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

我使用最多的命令是C-],它跳转到光标下的函数定义。你可以更经常地使用它来跟踪更多的电话。在那之后,C-o会带你回到一级,C-i会继续深入。

在我的。vimrc中总是有一行:

set tags=./tags;/

这将在当前目录中查找“标签”,并沿着树的根向上查找,直到找到一个。IOW,你可以在源树的任何位置而不仅仅是根结点。

我在macos中使用vim,原来的ctags不能很好地工作,所以我下载了latest并配置make make install它。 我在/usr/local/bin/ctags中安装ctgas(以保留原始的ctags)

"taglist
let Tlist_Ctags_Cmd = "/usr/local/bin/ctags"
let Tlist_WinWidth = 50
map <leader>ta :TlistToggle<cr>
map <leader>bta :!/usr/local/bin/ctags -R .<CR>
set tags=tags;/
map <M-j> <C-]>
map <M-k> <C-T>

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