Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get ctags working inside vim

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!

like image 247
JimmyBond Avatar asked Apr 04 '11 18:04

JimmyBond


3 Answers

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.

like image 176
Thomson Comer Avatar answered Oct 24 '22 02:10

Thomson Comer


Using exuberant ctags, I use something like this in my project's base directory (excluding the "log" directory):

ctags -R --exclude=log *
like image 6
coder_tim Avatar answered Oct 24 '22 04:10

coder_tim


You have to run the ctags command with the source files as arguments. This will create a tags file containing all information. Then you can open a file with vim, and e.g. press Ctrl-] when on a line with a function to jump to the code of that function. If vi isn't started in the same directory as the tag file, you can set it with :set tags=<file>

like image 5
steabert Avatar answered Oct 24 '22 04:10

steabert