Vim 自动生成 ctags [英] Vim auto-generate ctags

查看:39
本文介绍了Vim 自动生成 ctags的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

现在我的 .vimrc 中有以下内容:

au BufWritePost *.c,*.cpp,*.h !ctags -R

这有几个问题:

  1. 速度很慢 -- 为自上次生成标签以来未更改的文件重新生成标签.
  2. 我必须在写入文件后再次按下回车按钮,因为不可避免的按 Enter 或输入命令继续".

当您将这两个问题结合起来时,我最终过早地推送了额外的 Enter(在 ctags -R 完成之前),然后看到烦人的错误消息,不得不再次推送 Enter.

我知道这听起来没什么大不了的,但是随着我在某一天执行的文件写入量,它往往会变得非常烦人.必须有更好的方法来做到这一点!

解决方案

au BufWritePost *.c,*.cpp,*.h 静默!!ctags -R &

缺点是在完成之前您将没有有用的标签文件.只要您在 *nix 系统上,就可以在之前的 ctags 完成之前进行多次写入,但您应该对其进行测试.在 Windows 系统上,它不会把它放在后台,它会抱怨文件被锁定,直到第一个 ctags 完成(这应该不会在 vim 中引起问题,但你最终会得到一个稍微过时的标签文件).

注意,您可以按照 tonylo 的建议使用 --append 选项,但随后您必须禁用 tagbsearch,这可能意味着标签搜索需要更长的时间, 取决于标签文件的大小.

Right now I have the following in my .vimrc:

au BufWritePost *.c,*.cpp,*.h !ctags -R

There are a few problems with this:

  1. It's slow -- regenerates tags for files that haven't changed since the last tag generation.
  2. I have to push the enter button again after writing the file because of an inevitable "press Enter or type command to continue".

When you combine these two issues I end up pushing the additional enter too soon (before ctags -R has finished), then see the annoying error message, and have to push enter again.

I know it doesn't sound like a big deal, but with the amount of file writes I do on a given day it tends to get really annoying. There's gotta be a better way to do it!

解决方案

au BufWritePost *.c,*.cpp,*.h silent! !ctags -R &

The downside is that you won't have a useful tags file until it completes. As long as you're on a *nix system it should be ok to do multiple writes before the previous ctags has completed, but you should test that. On a Windows system it won't put it in the background and it'll complain that the file is locked until the first ctags finishes (which shouldn't cause problems in vim, but you'll end up with a slightly outdated tags file).

Note, you could use the --append option as tonylo suggests, but then you'll have to disable tagbsearch which could mean that tag searches take a lot longer, depending on the size of your tag file.

这篇关于Vim 自动生成 ctags的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆