ajpyles
ajpyles

Reputation: 628

vim tags - symbolic link

I have a project as follows:

/dir 
   dir1
   dir2 -> symbolic-link to /otherdir
       file1
   tags *

I have the following setup in .vimrc:

set tags=tags;/

Is there a way to keep this file structure without explicitly telling VIM the absolute path to tags?

Upvotes: 4

Views: 1965

Answers (3)

Hassek
Hassek

Reputation: 8995

You can append to the same ctags other tags, so for example if you want to ctag everything inside dir1 you would execute:

ctags -R *

and if you want to add some other tags from dir two:

ctags -R -a ~/path/to/dir2/*

-a is for appending.

Now what I do to always have my ctags no matter where I open my vim, is to add this line in my .vimrc:

set tags+=./tags;$HOME

this will look for tags in the current directory and will go down recursively to your home folder, if you would like it to search until the root folder or less just change $HOME for / or /path/to/root/project/

Upvotes: 3

romainl
romainl

Reputation: 196916

With this line in my ~/.vimrc and a similar layout as yours, tags related features (:ts, <C-]>, etc.) use the same tags file situated at the root of dir, alongside dir1 and dir2.

set tags=./tags,tags;$HOME

The tags file is first searched in the current file's directory, then in the cwd, then upwards until it reaches $HOME.

What does :echo tagfiles() say when you are editing file1? Here it says ['/home/romainl/Desktop/dir0/tags'].

EDIT

Throwing a symlink doesn't seem to change anything.

ENDEDIT

Upvotes: 1

Dan Hulme
Dan Hulme

Reputation: 15290

I think it's just a question of being in the right directory. When you start working in this project, use :cd /dir to get into the directory with the tags file, and make sure the autochdir option is turned off. Then when you edit a file inside dir2, the working directory will still be dir, and it will still find the same tags file.

If, on the other end, you end up with dir/dir2 as your working directory, that will actually mean you're in /otherdir, so when Vim looks for the tags file from there, it can't find it in that directory or in / . I suspect that's what's happening to you now.

You can see what directory you're in at any time with the :pwd command, just like in the shell.

Upvotes: 0

Related Questions