How to use Ctags with Vim

Productivity with Vim and Ctags

One way to use tags when doing vim:

If you have the following comment in your code

# ..
# app/controllers/claim_controller#import
#
# app/controllers/claim_controller
# ..

When you type gf while you are on the line you will get to go to the exact line that contain the code.

Working with more than one project at a time.

ctags will work very well with multiple projects. If you work on two or more projects and they reside under the same parent directory say projects

e.g.

~/projects/project_one
~/projects/project_two

If the two project share some common functionalities and you don’t know where to look then you could do the following:

# Go to the common root directory
cd ~/projects

# Create the ctags from this directory
ctag -R .

# Then open Vim or some editor that works with Ctag

If you are using Vim, you can then use the ctags the usual ways like:

:tag some_tag<CR>

Since you are working from the parent directory of the two projects, the tags from the all of them should be available for you to use.

Happy Hacking

Useful Links

comments powered by Disqus