Reputation: 31965
I just installed ctags
via homebrew and appended the following line in my ~/.vimrc
:
set tags=./tags,tags;$HOME
And then I ran /usr/local/bin/ctags -R .
on some of my directories and opened some files stored in the directories, then some of those scripts succeeded in importing tags file but others didn't.
For example, I opened up test.py
on my Python workspace, which I already run the above command in, and then I tried to put Ctrl+]
on my GVim, it looks like successfully imported the tags file.
I also opened up hello.go
located in ~/go/src/github.com/user/hello
, in which I already executed the above ctags
command, successfully imported the tags file. However, my test.rb
file, which I just put on the Go's directory in order to do test purpose, didn't import the tags file correctly.
Also, when I executed the ctags
command on ~/another_go_workspace/src
, and then opened up the file located in ~/another_go_workspace/src/hello/hello.go
, then the file didn't import the tags file... However, since I appended set tags=./tags,tags;$HOME
on my ~/.vimrc
, doesn't it automatically look for higher directories, right?
So what am I missing?
And if it doesn't import the tags file in higher directories, do I have to execute the ctag
command on EVERY directory, i.e. on ~/go/src/soccer_analysis
, ~/go/src/coffee
, ~/go/src/utility
, etc, etc... ?
Thanks.
Upvotes: 1
Views: 2379
Reputation: 24285
The problem may have been caused by a typo. I think
set tags=./tags,tags;$HOME
should be
set tags=./tags;,tags;$HOME
Upvotes: 0
Reputation:
No, vim doesn't go up directories to find tags files. I recommend you start vim from the top level directory (where you generated your tags), then traverse to whatever file you want.
vim go/src/coffee
Vim is capable of navigating filesystems nicely with commands like :Explore
.
EDIT: I was wrong, semicolon can be used to search upwards. See :help file-searching
Also, I noticed that you tried to add $HOME
to your tags, which isn't going to work for a number of reasons.
Documentation (:help 'tags'
) says:
Filenames for the tag command, separated by spaces or commas.
Therefore:
$HOME
is going to be treated like a tags fileSo the "correct" way of doing this would be:
set tags=./tags,tags,$HOME/tags
Even if you do that though, I don't think it's going to work. Tags files comprise primarily of 2 elements, a search pattern and a filename. If you generated the file from the top, all filenames will be relative to that directory.
So if you are deep down in some subdir, vim will try to open the file using the relative filepath from the top, starting at that subdir.
Upvotes: 0
Reputation: 196556
Your value for the tags
option is correct and your assumptions about its behaviour are correct too.
With your setting, set tags=./tags,tags;$HOME
, Vim will search for a tags
file in the directory of the current file first then for a tags
file from the working directory upward to $HOME
.
This allows you to generate a tags
file at the root of your project and be sure that Vim will pick it up wherever you are in your project and whatever the working directory is.
With the following structure and your current settings:
project/
bar/
bar.js
foo/
foo.js
project.js
tags
Vim should find tags
in all the following scenarios and their variants:
$ vim project.js
$ cd foo && vim foo.js
$ cd bar && vim bar.js
$ vim foo/foo.js
$ vim bar/bar.js
$ cd bar && vim bar.js ../project.js
Every time you add a new file to your project or write to an existing file, you must re-index your whole project. From what you wrote about the ruby file, it looks like you didn't run ctags after adding the file. Try this for a selection of files in your project: :echo tagfiles()
.
Upvotes: 5