How to get ctags working inside vim

JimmyBond picture JimmyBond · Apr 4, 2011 · Viewed 18.1k times · Source

I'm new to vim and wanted to get ctags integration working so I can more easily navigate a large java project.

I've pulled down the zip from source forge and extracted it but from here I'm not sure how to get it working with vim

Any help for a novice vim user would be great!

Answer

Thomson Comer picture Thomson Comer · May 27, 2014

As nobody has given one critical function in these answers, I'll provide one more slightly superior answer.

The easiest way to use ctags with vim is by calling:

ctags -R *

from the root of your source repository. This will generate a tags file in that same directory.

In your ~/.vimrc file, add this short block:

 " ctags optimization
 set autochdir
 set tags=tags;

" denotes a comment. set autochdir tells vim that if it doesn't find a tags file in the $PWD it will look in the directory parent for the tags file, recursively. set tags=tags; tells vim that the name of your tags file will always be the same as the default tags file generated by ctags.

So long as you run ctags -R * in your root source directory the first time and occasionally to update it (if you pull new changes from others) then you'll always have a fast and intuitive ctags symbol lookup in vim.