Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vim: Difficulty setting up ctags. Source in subdirectories don't see tags file in project root

Tags:

vim

ctags

I'm trying to get setup with (exuberant) ctags on Vim today and am having difficulty getting it to work properly. I generate my ctags file on the command line with with:

cd myproj ctags -R 

This puts the tags file in myproj root. However, Vim only seems to read from this tags file when I'm working on source that reside in root. As I navigate to deeper directories, if I try to jump to a tag using <C-]>, I get:

E433: No tags file E426: tag not found: MyClassName 

I've verified that MyClassName does have a tag in the tags file, it's just that Vim doesn't see it. Can someone please explain how to configure Vim to reference the root's tags file?

Thanks.

like image 723
Thomas Avatar asked Feb 16 '11 14:02

Thomas


People also ask

How do I enable tags in Vim?

You can position the cursor over the tag and press g Ctrl-]. You can visually select a text and press g Ctrl-] to jump or list the matching tags. You can use the 'stjump' ex command. This will open the matching or selected tag from the tag list in a new window.

Is a directory ctags?

ctags creates a file named tags in the current directory. It summarizes the locations of various objects in the C source files named on the command line.


2 Answers

add this to .vimrc file set tags=tags;/

This will check the current folder for tags file and keep going one directory up all the way to the root folder.

So you can be in any sub-folder in your project and it'll be able to find the tags files.

like image 65
Amjith Avatar answered Sep 29 '22 06:09

Amjith


There is an option to tell Vim where to look for tag file.

I use the following configuration:

" search first in current directory then file directory for tag file set tags=tags,./tags 

Extract from help :

When a tag file name starts with "./", the '.' is replaced with the path of the current file. This makes it possible to use a tags file in the directory where the current file is (no matter what the current directory is). The idea of using "./" is that you can define which tag file is searched first: In the current directory ("tags,./tags") or in the directory of the current file ("./tags,tags").

For example: :set tags=./tags,tags,/home/user/commontags

And I keep my current working directory in the top project directory where my tagsfile is generated.

Use :pwd and then :cd myproj (inside Vim) to go to the directory containing your tags file.

See :help tags-option for more information on tags path.

You issue is probably that you are either in the wrong directory, or your tags option is not properly set.

like image 43
Xavier T. Avatar answered Sep 29 '22 06:09

Xavier T.