I know that it is possible to use Ctrl+] to jump to a definition in Vim and this can work in conjunction whith either ctags or Cscope. I am looking for a more accurate alternative to both ctags and Cscope when working PHP. Sometimes there are multiple possible results to choose from or false positives. I only want to jump to the actual definition of whatever is under the cursor. Ideally this should work for variables, functions, constants, and classes.
I don't see why this can't be done by analyzing the files. I have finally overcome just about every other annoyance/misunderstanding I have with Vim by learning and customizing, so if I could nail this one it would be awesome.
Also, do other's agree that Cscope and ctags are not accurate enough for PHP or am I doing something wrong?
UPDATE
4 years later, I am still using Vim with PHP, and still having this problem. I have tried eclim, ctags, exubarant-ctags, universal-ctags, and cscope. I have tried passing various arguments to these programs to get them to generate better tags. The experience is very poor for all of these options.
But I understand the problem much better now. There might be nothing wrong with the tags generated by these programs. The problem seems to be that when you press Ctrl + ] in Vim or Neovim, it just looks for a tag by that name. It is not looking at the context of the file you are editing to see which tag by that name it should use. It does not even understand what language you are editing, and look for tags from code in that language.
Is there a way to make vim search through the tags file more intelligently, based on the context, and then jump to the most likely location? You know, like what would happen inside a good IDE?
As a C++ developer I had similar issues for a long time. Until, that is, I reorganized my approach to using tag files under Vim a few years ago. The trick that made it work for me was to generate separate tag files for different slices of code: my project, various external code libraries, etc... I then had to set the 'tags' option to look for the files in a priority order, with my local code project files coming first and then working outward from there with the system header files being LAST.
In my case, I had separate tag files for each of these and listed in this order in the 'tags' option:
I'm not a PHP developer, but again the main mistake I made for a long time was just generating a single tags file FOR EVERYTHING. I'd have upwards of 30 tags to search through many times (using the :tag command). If you generate multiple tags files you have much more control over the search order of tags and thus what tags in which files are found.
See if that works for you. It did for me.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With