First is the "go to file" feature. If you move the cursor onto a file name, and type gf, you'll be taken to that file. To return to the previous file, press Control-o. The file opens are kept on a stack, so you can drill down into file, and climb back out. This is useful for reading code with "includes".
| keys | action |
| gf | go to ffile under the cursor, and push the current file onto the file stack |
| Control-o | Pop the file from the file stack and return to it. |
When you move the cursor onto a word, and press Control-], it looks up the word in tags, and opens up the file with the definition, and puts the cursor at the definition. The tags are kept on a stack, and you can back out of the file by pressing Control-t. This is useful if you're reading a header file or some code, and want to know what a function does.
Sometimes, a tag will have multiple definitions. You usually discover this when you use C-] and go to a useless line. You can find an alternative tag definition by typing :ts and picking the correct tag definition.
Alternatively, you can type g] and get a list of the tags defined for the word under the cursor. Use this if you're aware that the tag has multiple definitions.
| keys | action |
| Control-] | Follow tag. Looks for the word under the cursor in the tags database, and open the file where the tag is defined. Pushes current file onto the tag stack. |
| Control-t | Pop file from tag stack and open it. |
| :ts | Show and select tag definitions for the word on the top of the tag stack. Use this if you follow a tag and the definition seems wrong. |
| g] | Show and select tag definitions for the word under the cursor. |
When you install exuberant-ctags it will install two commands ctags and etags. Calling it at ctags will produce a "tags" file in the classic format, which is used by vim. Calling it as etags will produce a "TAGS" file using a newer binary format used by emacs. So, use "ctags".
Here are some sample commands:
ctags -RRecursively build the tags file from all the sources starting with the current directory.
ctags --langmap=php:.php.inc -R *Run this in the Drupal root directory to build the tags file. Drupal's code uses the .inc suffix on files in the includes directory.
Generally, I'll create a script to refresh the tags file, and make sure ALL the files I'm using are included in the database. As the project grows, I re-run the script to rebuild the db. Simple.
Here's a script to rebuild the tags file for Drupal:
#! /bin/bash cd ~/Src/drupal-6.19/ ctags --langmap=php:.php.inc -R *