views:

188

answers:

2

Hi,

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 in 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.

A: 

You could try the OmniCppComplete plugin.

m42a
I might not have been clear in my original message, but it is the OmniCppComplete plugin that I'm already using. I've searched through the help to see if there's support for what I require but I can't seem to find anything. Do you know any different?
thoughton
It does that when I use it. Make sure you're completing with <C-x><C-o> rather than <C-n> or <C-x><C-n> or <C-x><C-]>. I also have the following options set:let OmniCpp_MayCompleteScope = 1let OmniCpp_ShowScopeInAbbr = 1let OmniCpp_ShowPrototypeInAbbr = 1But those shouldn't change anything.
m42a
+1  A: 

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.

thoughton