Text Editors and CTags

A while ago I talked about IDEs vs Text Editors why-you-should-learn-a-text-editor. This may have inspired you to try out vim.

If you are coming from an IDE background, then you must have noticed a key weakness in vim. That is that you can not immediately jump to function/class definitions. This can be quite a challenge for large projects. Cue in ctags

Tag Cloud

Tag Cloud

Ctags supports 40+ languages. You can almost be certain your language is supported.

To install ctags on a debian machine run.

sudo apt-get install exuberant-ctags

This should install the latest version of ctags.

Next you need to index your project so that vim and any other text editor for that matter, can consume it.

To do this navigate to the root of your folder and run ctags -R .

cd /var/www/{project_root}
ctags -R .

You could ofcos run the bash ctags -R command from any directory as long as you provided the correct path.

This is likely to take quite a while to complete. Luckily ctags is not a noisy utility and thus you can run

ctags -R . &

To push it to the background. This way you can continue working.

When the process is done you will have a shiny new folder called tags. Do not delete this folder, but consider adding it to your .gitignre file. See what_to_ignore

Now that your tags are ready you can use them in vim as follows

  1. Navigate your document such that the cursor is on top of the term which you would like to navigate to its position
  2. Press <c-]> If the definition exists this should jump you to the file
  3. You can jump back by pressing <c-i> once done reviewing the source document.

It is important to note that you need to continue updating your tags index whenever you add new classes/functions. The process is still the same really, how you do it thou is upto you.

  • For php developers, you can put the tags generator in your composer.json file in the post-update-cmd section
  • Put the command in your vim MakeFile so that update can be done when building the app
  • Use a plugin such as easy tags
  • Any script that best fits your workflow

Hope this eases your path to vim mastery.

Till next time, happy tagging!.


Published by


Software Project Manager