davidvandebunte
davidvandebunte

Reputation: 1486

How do I jump to class-qualified tags in VIM?

In this answer, we're given the valuable tip to include--extra=+q when we're working with C++ code. What this answer doesn't address is the comment bewailing how difficult is to use the class-qualified tags.

You can search for a qualified tag with :tag /pattern but this solution is cumbersome. Is there any way to get the correct tag with the default CTRL-]? Solutions that are "just OK" are also welcome.

Upvotes: 0

Views: 340

Answers (3)

gdupras
gdupras

Reputation: 751

Do

:set iskeyword+=:

then Vim sees myclass::mymethod as one word. You can then do <C-]> anywhere on it to jump to the class-qualified tag.

Upvotes: 0

Rudy Albachten
Rudy Albachten

Reputation: 111

If you use a visual selection and include the class qualifier, the normal tag jump commands will include the whole visual selection in the lookup.

I use C-V to start a visual selection, move to the end of the name, and then use C-], or g then ] as usual

Also, vi -t some_class::some_method works on the command line

Upvotes: 0

romainl
romainl

Reputation: 196596

Assuming the workaround mentioned in that comment satisfies you, you should use :tjump /pattern instead of :tag /pattern. It behaves like :tag /pattern when there's only one match and like :tselect /pattern when there are several matches.

The normal mode equivalent of :tjump is g<C-]> but it behaves like :tjump pattern, not like :tjump /pattern and there's no way to make it work like that except remapping it:

nnoremap g<C-]> :tjump /<C-r><C-a><CR>

Upvotes: 1

Related Questions