Vim - ctags: tag not found - vim

I want to use Ctags for a Zend framework project. I executed this command : ctags -R ./* ../ZendFramework/*to create a list of tags, but the problem is when I press Ctrl-] on a class or method I get this error: ctags: tag not found
I checked the tags file and all classes/methods/variables are listed. The tags files is located in the root of the project. Should I load it manullay when I open a file?

Yes, you should tell Vim where to find your tags file with something like:
:set tags=/path/to/tags
This is not very optimal, though. This line in your ~/.vimrc should help:
set tags=./tags,tags;$HOME
It tells Vim to look for a tags file in the directory of the current file, in the current directory and up and up until your $HOME (that's the meaning of the semicolon), stopping on the first hit.

The 'tags' variable must point to your tags file. See :help 'tags'.
An example to add the path to your tags file:
:set tags+=$HOME/yourpath/tags

I Faced the same problem few days ago. I was applying ctags shortcuts in a .c file and I was getting this error while doing so. I googled the error and found that the ctags was not installed. But the ctags is present in my server. I tried moving the ctag folder to the trunk which i'm currently working and this trick resolved my problem.
steps:
go to your home folder and enter "where is ctags"
it will display the path of the ctags file.
copy that file and move the same to the directory which you are working in
i hope this will resolve your issue.

Related

How can I make vim not follow links?

I have a linux checkout directory with a module inside called learnldd
./linux/learnldd/hello/hello.c
I have a tags file called TAGS in my linux checkout
./linux/TAGS
When I open hello.c in vim, vim cannot find the tags file because learnldd is actually a link from
~/Repos/learnldd -> ~/Repos/linux/learnldd
So, when vim is searching for my tags file a la
:set tags=./TAGS;
it ends up looking in the actual directory and it's parents, rather than the linked one. If I
:cd ~/Repos/linux/learnldd
:pwd
vim follows the directory and reports that I'm in
cd ~/Repos/linux/learnldd
Is this a limitation on vim or is there some way around this without changing my link setup?
Use the environment variable $PWD, which does not follow links. In your ~/.vimrc:
set tags=$PWD/TAGS;

No tags file in GVim on some file but not on others

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.
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().
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:
The delimiter is incorrect
$HOME is going to be treated like a tags file
So 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.
The problem may have been caused by a typo. I think
set tags=./tags,tags;$HOME
should be
set tags=./tags;,tags;$HOME

./file versus file

I'm reading a tutorial on how to set up Exuberant Ctags for a multi-level directory structure, and I saw the following line,
Configure your editor to read the local tag file first, then consult
the global tag file when not found in the local tag file. In Vim, this
is done as follows: :set tags=./tags,tags,~/project/tags
Question is: (and this is probably more general than just Ctags) Why are ./tags and tags both specified as places to look? Don't they evaluate to the same thing?
No. From :help 'tags':
When a file name starts with "./", the '.' is replaced with the path
of the current file. But only when the 'd' flag is not included in
'cpoptions'.
So ./tags searchs for the file, not in the current directory, but in the directory where the current file is located.
However, tags does search for the file in the current directory.
Yes, I'd also expect it to work the other way around...

How to get ctags working inside vim

I'm new to vim and wanted to get ctags integration working so I can more easily navigate a large java project.
I've pulled down the zip from source forge and extracted it but from here I'm not sure how to get it working with vim
Any help for a novice vim user would be great!
As nobody has given one critical function in these answers, I'll provide one more slightly superior answer.
The easiest way to use ctags with vim is by calling:
ctags -R *
from the root of your source repository. This will generate a tags file in that same directory.
In your ~/.vimrc file, add this short block:
" ctags optimization
set autochdir
set tags=tags;
" denotes a comment. set autochdir tells vim that if it doesn't find a tags file in the $PWD it will look in the directory parent for the tags file, recursively. set tags=tags; tells vim that the name of your tags file will always be the same as the default tags file generated by ctags.
So long as you run ctags -R * in your root source directory the first time and occasionally to update it (if you pull new changes from others) then you'll always have a fast and intuitive ctags symbol lookup in vim.
Using exuberant ctags, I use something like this in my project's base directory (excluding the "log" directory):
ctags -R --exclude=log *
You have to run the ctags command with the source files as arguments. This will create a tags file containing all information. Then you can open a file with vim, and e.g. press Ctrl-] when on a line with a function to jump to the code of that function. If vi isn't started in the same directory as the tag file, you can set it with :set tags=<file>
This is what I'm doing:
ctags -n -f [OUTPUT] [SOURCE] to generate the tags (NOTE: the -n applies to me but may not be necessary for your usage)
exec "set tags=" . [OUTPUT] inside of .vimrc to let vim become of aware of the tags
EDIT: I'm using
Exuberant Ctags 5.5.2
VIM 6.1
Additional info:
See ctags usages here
Tips and tricks from SO
look at this article: vim-easytags. i haven't tried this, but it looks quite good. manually creating and updating tags was really annoying. hope this will help. :)

ctags problem when generating tags for .h and .c file in two different directory

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!
In vim, try typing:
:pwd
: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).
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.

Resources