13
Oct

Programmers Tool: Ctag Navigation with vim

If you’re a programmer, you might be interested in taking advantage of the ctags utility to quickly navigate through your source code in a text editor such as VIM.

Ctags is a utility or program that creates an index (aka tag) file of names found in source and header files of various programming languages. This index includes things such as functions, variables, class members, macros, etc. This is great because vim can take advantage of this index and you can more quickly navigate through source files. For more information, wikipedia has a nice article on it here.

To start using ctags, you must first have the ctags utility. A quick check would be to just type ctags --version in the terminal:

[email protected]> ctags --version
ctags (GNU Emacs 23.1)
Copyright (C) 2009 Free Software Foundation, Inc.
This program is distributed under the terms in ETAGS.README

If you have it, then we can immediately start using it. First, build the index by running in the directory where you keep the source code:

ctags source.c

If you’d like to be able to recursively scan all of your source files, you must insure that you’re using the exuberant ctags utility. In a Debian based system, this is simply done with:

sudo apt-get install exuberant-ctags
sudo update-alternatives –config ctags

Then, open the source in vim and use ctrl ] to jump into the tag and ctrl t to jump out of the tag.

There’s quite a bit of information available out there on using these tools together. I would recommend taking a look around. Here are a few that I found:
Stackoverflow: Vim and Ctags tips and tricks
Linux.byexamples: Vim with Ctags

Feel free to donate if this post prevented any headaches! Another way to show your appreciation is to take a gander at these relative ads that you may be interested in:


There's 2 Comments So Far

Share your thoughts, leave a comment!