Assuming I have a code directory structure as follows:
/top
/second
/core
a.pl
b.pl
c.pl
/common
d.pl
e.pl
/util
f.pl
g.pl
h.pl
Where should I run the ctags
so that I can jump to function definitions via vi
?
For example I had:
/dir
/perl
a.pl
and I run in dir
the command ctags -R perl
but in a.pl
I could not jump to a function definition that existed in the same file.
If I did ctags -R .
inside the perl
directory it worked.
So I can not understand the pattern. Should I run ctags
in core, common,util
? What if my code base is huge? Would I really need to run it in each directory?
Normally you would use just one tags
file located in the root directory of your project.
For example, to tag the whole of Vim's own source code, located in ~/src/vim-7.3
, you navigate to that directory and generate the tags file there.
$ cd ~/src/vim-7.3
$ ctags -R
That's all.
You can do the same from inside Vim, of course. Start Vim and then type:
:cd ~/src/vim-7.3
:!ctags -R
Check that you have the correct 'tags'
setting. Default is ./tags,tags
, meaning Vim will look for a tags
file in the current directory.
Make sure to read :h 'tags'
in its entirety. You can instruct Vim to look for tags
files deep in the directory tree by giving patterns containing wildcards.
One more thing: For this approach to work, Vim's current working directory must remain at the root at all times. If you have some option like 'autochdir'
set or constantly switch directories yourself, then the tags
obviously won't be found.