tags:

views:

189

answers:

2

Now I have two directory, all of header files *.h are included in directory /inc, while all of c file *.c are stored in /src directory.

The directory just like this, (/project is a up level directory):

/project-- |----/inc
           |----/src

I want to use ctrl+] to locate definition of one parameter or one function in a source file like example.c. How to generate those tags?

My method is:

(1) cd to the /project directory

(2) ctags inc/*.h src/*.c

Then a tags file is generated there, however, when I open a example file and using "Ctrl+]", it cannot lead me to its definition. Why???

Do I need to generate a tags file under /src???

Any help? Many thanks!

+2  A: 

Go to /project, and use the command "ctags -R ." In your .vimrc, put the command "set tags=/project/tags". Exit vim and enter it again. Tags should now work.

Paul Tomblin
if I add /project/tags into .vimrc, then everything in the future will affect by this sentence, right? Besides, /project/tags is part of the path, do I need to add the whole path of set tags=~/abcd/project/tags ??
MaiTiano
Yes, putting it in the .vimrc will affect everything until you remove it. I have a bunch of tags files separated by commas in my .vimrc. And yes, you need the full path. Your question mentioned /project, so I assumed it was the full path.
Paul Tomblin
Thanks for your detailed and kind answer. I have learned a lot from you. :)
MaiTiano
since you are such a expert and Tim may need more reputation, I think you may not mind if my giving accepted answer to Tim. :)
MaiTiano
That's fine. Whichever answer you found more helpful.
Paul Tomblin
+2  A: 

In vim, try typing:

  1. :pwd
  2. :set tags

Verify that the path to your tagfile is present in output of 2, relative to the path that is the output of 1.

NOTE: You can set the tags variable as part of your local .vimrc.

UPDATE: It is common to set tags to a pattern like tags,../tags,../../tags. With this pattern, vim will use the first tags file that it finds your folder structure (again relative to your pwd).

Tim Henigan
after :set tags it gives something like this " tags=./tags,./TAGS,tags,TAGS "... is it right?
MaiTiano
@MiaTiano: This value of `tags` tells vim to search for the tags file in the same directory that you opened your file. I bet if you added `../tags` to the search path (as noted in my UPDATE above) it would work for you. The bottom line is that vim starts looking for the tags from from `pwd`. The file names it searches for are listed in `:set tags`.
Tim Henigan
thanks very very very much. :)
MaiTiano
may I know what is the difference between ./tags and ./TAGS ???
MaiTiano
@MiaTiano: See the documentation of the '-f' option at http://ctags.sourceforge.net/ctags.html. From `ctags`, the output file name "...default is 'tags', or 'TAGS' when running in etags mode".
Tim Henigan