2

I have the following php file:

namespace App\Validator;

use Symfony\Component\Validator\Constraint;  // #1

class MyValidator // ...
{
    public function validate(Constraint /* #2 */ $constraint): void
    {
        // ...
    }
}

I have generated all tags with exuberant ctags (v5.9) using the command ctags -R ..

Whenever I put my vim cursor on either #1 or #2 and try to navigate to the Symfony\Component\Validator\Constraint class using tselect (actual key pressed: C-]), the current buffer is loaded with the PHPUnit\Framework\Constraint class instead of Symfony\Component\Validator\Constraint.

Is this a ctags issue or a vim issue ? What should I do to generate tags that understand php namespace ?

1

1 Answer 1

3

<C-]> is equivalent to :tag <keyword>, not to :tselect <keyword>, the normal mode equivalent of which would be g].

The end result of $ ctags -R . is a tags file that contains a list of tags found under the working directory. :tag and :tselect work differently:

  • :tag <keyword> (and thus <C-]>) jumps to the first matching tag found in that tags file,
  • :tselect <keyword> (and thus g]) displays a list of the matching tags found in that tags file.

In your case, <C-]> jumps to the first Constraint that was found by ctags, which is the expected behavior.

If you use g], you should get a list of potential tags and thus be able to jump to the appropriate one.

That is, of course, if your tags file includes what you are looking for.

I recommend :tjump <keyword> (and thus g<C-]>) instead of either, because it combines the advantages of both:

  • if there is only one matching tag, jump to it like :tag <keyword>,
  • if there are more than one, display a list like :tselect <keyword>.

See :help :tselect, :help :tjump, and :help :tag.

1
  • 1
    illuminating answer; thank you
    – kjones
    Jan 25 at 19:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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