简体   繁体   English

是否可以在Vim中使用不同的标签文件进行omnicomplete和一般标签浏览?

[英]Is it possible to use different tags files for omnicomplete and general tag browsing in Vim?

I've been using ctags in Vim for years, but I've only just discovered omnicomplete. 我多年来一直在Vim中使用ctags,但我刚刚发现了omnicomplete。 (It seems good.) (看起来不错。)

However, I have a problem: to get omnicomplete working properly I have to use the --extra=+q option when generating the tags, which is fine, but this then changes the behaviour of general tag browsing in ways that I do not like. 但是,我有一个问题:要使omnicomplete正常工作,我必须在生成标签时使用--extra = + q选项,这很好,但这会改变一般标签浏览的行为,我不喜欢这种方式。

For example, when tab-completing tag names in Vim I don't want to tag "into" the "hierarchies" of classes - that is, when tab completing "Clas" get "ClassA, ClassA::var1, ClassA::var2, ClassB", instead of "ClassA, ClassB" - but that's what happens when using --extra=+q. 例如,当在Vim中完成标签名称标签时,我不想标记“进入”类的“层次结构” - 也就是说,当完成“Clas”的标签获得“ClassA,ClassA :: var1,ClassA :: var2”时,ClassB“,而不是”ClassA,ClassB“ - 但这是使用--extra = + q时发生的情况。

So I guess I'm after one of two things. 所以我想我是在完成两件事之一。 Either: 1. The ability to disable tab-completing into "tag hierarchies" even though those hierarchies do exist in the tags file. 要么:1。禁用制表符完成“标记层次结构”的功能,即使这些层次结构确实存在于标记文件中。 Or, 2. The ability to use differently named tags files (ie. generated with different options) for omnicomplete and general tag browsing. 或者,2。使用不同命名的标签文件(即使用不同选项生成)进行omnicomplete和一般标签浏览的能力。

Any ideas would be much appreciated! 任何想法将不胜感激!

Cheers, 干杯,

thoughton. thoughton。

OK, I think I've actually come up with an answer to my own question. 好吧,我想我实际上已经找到了自己问题的答案。

Firstly, I generate two tags files: tags_c_vim and tags_c_omni. 首先,我生成两个标签文件:tags_c_vim和tags_c_omni。

In my _vimrc I have: 在我的_vimrc中我有:

let tags_vim='tags_c_vim'
let tags_omni='tags_c_omni'

exe "set tags=".tags_vim

to setup some variables pointing to the different tags files, and to set the "vim" tags to be the default tags. 设置一些指向不同标签文件的变量,并将“vim”标签设置为默认标签。

Then I also have this, again in the _vimrc: 然后我再次在_vimrc中有这个:

imap <F8> <ESC>:exe "set tags=".tags_omni<CR>a<C-X><C-O>
autocmd InsertLeave * if pumvisible() == 0|exe "set tags=".tags_vim|endif

the first line here maps F8 so it changes the tags setting to point to the "omni" tags before then invoking the omnicomplete popup menu, and the second line resets the tags setting to the "vim" tags when insert mode is next left after the popup has closed. 这里的第一行映射F8,因此它将标签设置更改为指向“omni”标签,然后再调用omnicomplete弹出菜单,第二行将标签设置重置为“vim”标签,此时插入模式位于弹出窗口已关闭。

It's going to need some extensive use to make sure it's robust enough, but it does seem to work after some quick testing. 它需要一些广泛的用途,以确保它足够强大,但它似乎在经过一些快速测试后工作。

Two improvements I'd still like to make: 我还想做两个改进:

  1. Map the setting of the "omni" tags to the omnicomplete CX,CO command instead of a new F8 mapping. 将“omni”标签的设置映射到omnicomplete CX,CO命令而不是新的F8映射。 (I think I need to set the tags and then call omni#cpp#maycomplete#Complete(), but I couldn't work out how to do this) (我想我需要设置标签,然后调用omni #cpp#maycomplete#Complete(),但我无法弄清楚如何做到这一点)
  2. Hook the resetting of the "vim" tags into either omnicomplete itself finishing or the popup menu closing 将“vim”标签重置为omnicomplete本身完成或弹出菜单关闭

Anyway, I just thought I'd share. 无论如何,我只是想我会分享。

Cheers, 干杯,

thoughton. thoughton。

您可以尝试OmniCppComplete插件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM