2

Problem: ^] doesn't work if cursor is on a function name prefixed with its package.


I am using ctags and by reading the tags file generated I ensured that the sub is indexed in the tags file, like:

a_func_like_this lib/Package/Module.pm /^ sub a_func_like_this {$/; s"

So it works if my cursor is on a_func_like_this.

However if the full name is specified (along with its module) like Package::Module::a_func_like_this, ^] would search for the full name which is not indexed by ctags.

It's like the default behaviour of ^] is yiw :tag <C-r>"<CR>. Which implies that Package::Module::a_func_like_this is being searched and thus returns no result.

As a workaround I want it to just get the part after :: if that presents in the Inner Word.

That said, even with such work around, I may have to manually select the correct version of a_func_like_this even though the exact file I am looking for is clearly Package::Module (the part discarded). I guess vi should have something smarter for tag jumping.

How should I approach this?

  • I am sorry for the problem being unclear. The mapping is working - it's like its default behavior is yaw :tag <C-r>"<CR>, which doesn't work for full function names because the Package:: part is captured by yaw. A workaround is to use yiw however I may have to manually find the correct version of the function though the package is explicitly seen. Any ideas to make the tag jumping smarter? – Sunny Pun Nov 3 '17 at 0:56
  • 1
    Maybe the proper solution involves a config of ctags instead of a vim issue? – Mass Nov 3 '17 at 1:45
  • I have just read the ctags manual. Seems that the --fields option may be useful. I'll instead try YouCompleteMe to see if that's handled better there... – Sunny Pun Nov 3 '17 at 4:20
1

Thanks I have figured it out.

Instead of a plain ctags -R, run ctags -R --extra=+q which also adds the prefix-ed version of the methods into the tags file.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.