4

I've been using PHP Storm IDE for some time and I want to try out Vim. PHP Storm automatically allowed me to jump to classess/interfaces defined somewhere in my code (by use and implements statements, and alike) by double clicking on them. Can I do the same in Vim?

For example, I am in /app/models/User.php that implements UserInterface defined in app/interfaces/UserInterface.php. I want to double click on that name and it would automatically take me to that file.

  • There are a few plugins which implement this, such as tagbar and taglist. – EvergreenTree Jun 23 '15 at 16:15
  • In 2019 I would recommend installing the phpactor plugin – vivoconunxino Jan 10 at 15:35
5

You can use the external program exuberant cTags to help you doing that: It will create a tags file indexing the keywords of your codebase and allow you to navigate through them.

(The first steps comes from another answer)

  • Install exuberant cTags: $ sudo apt-get install exuberant-ctags (or the equivalent command for your distribution).

  • Generate the tags file: $ ctags *.php a file named tags should be generated on your folder.

  • Let Vim knows where is your tags file: :tags=./tags,tags with these settings Vim looks for a tags file in the directory of the current file and in the working directory. Note that you can use :set tags? to check your current configuration.

  • Jump from keyword to declaration and inversely with <C-]> and g<C-]>

  • Open a preview window showing the declaration with <C-w>}

I've never used it with php but it should work just like with other languages

  • I started using preview windows for this kind of thing, by using ctrl-w }. – Vitor Jun 24 '15 at 11:17
  • @Vitor I didn't know this feature but that seems to be pretty useful! – statox Jun 24 '15 at 11:59

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.