开发者

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. (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 i开发者_StackOverflow中文版n ways that I do not like.

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.

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. Or, 2. The ability to use differently named tags files (ie. generated with different options) for omnicomplete and general tag browsing.

Any ideas would be much appreciated!

Cheers,

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.

In my _vimrc I have:

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.

Then I also have this, again in the _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.

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 C-X,C-O command instead of a new F8 mapping. (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)
  2. Hook the resetting of the "vim" tags into either omnicomplete itself finishing or the popup menu closing

Anyway, I just thought I'd share.

Cheers,

thoughton.


You could try the OmniCppComplete plugin.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜