vim with ctags
December 10th, 2006 mysurface Posted in ctags, Developer, ln, vi, vim | Hits: 143030 | 22 Comments »
If you are c/c++ programmer and vim user, maybe know ctags. Most of the time, source code are distributed to many folders and each of them consist of numbers of .cc/.c and .h. Sometimes to search the definition of a function, class, enums etc by using “/” is inefficient. ctags allow fast jumping to function call even the function definition source code are from other directories.
In order to use ctags, first run the command at destination directory where the source codes are located.
ctags -R *
-R is to recursively goes across all the directories, and a ‘tags’ file will be created. You may now jump from function call to function definition, by pressing ctrl ] on the keyword.
Let say when you discover a function call which you wanna see the definition, simply point the cursor to that function and press ctrl ] and it will brings you there. If you wants to go back to where you came from, simply press ctrl t. Instead of ctrl t, I like to use ctrl i and ctrl o to travel to forward and backward of the check points.
The case is sometimes, you want to jump to the function declaration which the header files is not under the same folder of your source code. You can’t because ctags won’t know where is the function call come from.
With simple trick, you can make wonders. create a synlink under the folder of your source code to link to a specific directory or header files. Let say I wanna refers the curses.h which is located at /usr/include/, I can create a symlink in my source code folder.
ln -s /usr/include/curses.h curses.h
Check out more about symlink at here.
Then perform ctags again
ctags -R *
When you add a function at your class or module, you need to run ctags again too.







November 1st, 2007 at 11:21 am
I am using cygwin.
I opened cygwin bash and at the top of directory structure (windows) where the code is present, I typed “ctags -R *” and I got a segmentation fault (core dumped).
Has anyone seen this before?
November 1st, 2007 at 2:11 pm
SurajV: oops. how about doing ctags -R * at a folder? For examples c:/MyProgramming ?
May 30th, 2008 at 4:42 pm
Hi, I know it’s an old post, but I’m really interested in integrating ctags in Vim. We are using Visual Studio.NET at work cauz we’re develop web sites in C#.
I want to show to my boss that Vim can be a really relevant customized IDE :) (i’m developping on PHP at home).
I’m using gvim on Windows XP, I downloaded the ctags .zip file from http://ctags.sourceforge.net/ and try to use the ctags.exe in it, but it doesnt work.
Do I have to compile some file ? (there are a lot of *.c, *.h and .mak in it but i dont know what to do with them)
Thx in advance.
For those who are interested in developping in PHP using vim, here is a REALLY nice site which show a lot of features that turn vim into an IDE-like, similar to Zend, Ecclipse etc… -> http://www.koch.ro/blog/index.php?/archives/63-VIM-an-a-PHP-IDE.html
Vi Rox
May 31st, 2008 at 10:14 am
@shine458
I don’t have Windows machine for me to try it out. You probably need to configure the vimrc, add in this line:
and run ctags.exe * -R in your folders.
February 12th, 2009 at 8:45 am
Am I misunderstanding something? On Ubuntu, -R is not Recursive…
-R, –no-regex
Don’t do any more regexp matching on the following files. May be freely intermixed
with filenames and the –regex option.
$ ctags –version
ctags (GNU Emacs 22.1)
So all I end up with is a ‘tags’ file for the current directory. The man page doesn’t even have the word ‘recursive’ in it. :-\
February 13th, 2009 at 6:20 pm
I opened cygwin bash and at the top of directory structure (windows) where the code is present, I typed “ctags -R *” and I got a segmentation fault (core dumped).
Has anyone seen this before?
+=====> try with different version.
February 15th, 2009 at 9:16 am
@Daevid: probably your ctags aren’t exuberant enough :)
There’s probably a package exuberant-ctags or something in the repos, or failing that, http://ctags.sourceforge.net
I thought Ubuntu had the Right Version installed by default, but apparently not…
February 15th, 2009 at 9:18 am
(Incidentally, the man page still doesn’t have the word ‘recursive’, because the long form of the option is recurse. So maybe it’s called that in emacs’ ctags, and you might want to check that first.)
March 13th, 2009 at 9:17 am
Yes, it works under Ubuntu. When I create my tags using “ctags -R *”, I do so in the top level of my working directory. This puts the “tags” file in the top level. To overcome the problem with multiple sub-directories not finding the tags, I add the following to my ~/.vimrc file:
:set tags=/path/to/tags
You could do this each time you open vim, but I’m lazy. Obviously, this won’t work if you are working on multiple projects. Then you could use a relative directory instead.
September 30th, 2009 at 1:24 am
If ‘-R’ doesn’t work for you, then you probably have the wrong ctags program installed. Try this:
sudo apt-get install exuberant-ctags
sudo update-alternatives –config ctags
…then choose ctags-exuberant. Then ‘-R’ should work! BTW, exuberant-ctags is the version that the vim team makes :~)
November 3rd, 2009 at 1:35 am
Thanks Aaron. it worked. looks like i didn’t install the correct ctags.. i reinstalled using
sudo apt-get install exuberant-ctags
and it worked. it had correct definition for -R option.
July 25th, 2010 at 11:49 am
Thanks for this post! Just getting started using tags, seem very useful.
I also found you can start vim and go directly to a tag:
vi -t tag
Or when in a file, without needing to find a reference to it:
:ta tag
January 26th, 2011 at 7:08 am
Would you be all in favour of exchanging links?
March 23rd, 2011 at 3:32 pm
Thanks this was very helpful
March 23rd, 2011 at 3:35 pm
Ctags are very helpful in parsing through the code. thanks a lot again
April 10th, 2011 at 1:54 am
The link was so helpful while browsing the Linux Kernel source code… Thanks a lot !!
May 18th, 2011 at 11:20 pm
Hi,what an excellent article this is,I found it on yahoo and I like it very much,I agree with what you have said, lots of things will be learned form your site,but I still have some questions with the last part,can you explain it for me ?I need your answer,and I will be back again!
June 14th, 2011 at 1:16 pm
thanks this site is very helpful for linux kernel source code
June 14th, 2011 at 1:22 pm
thanks a lot this link is very helpful to me thanks……………………..
November 10th, 2011 at 4:07 pm
Thanks alot
This link is very useful to me…………….
March 30th, 2012 at 1:17 pm
i installed c-tags using “sudo apt-get install exuberant-ctags” command but it shows me
usage: ctags [flags] filenames…
-Dword Ignore “word” — handy for parameter macro name
-F Use /regexp/ (default)
-B Use ?regexp? instead of /regexp/
-N Use line numbers instead of /regexp/
-g Store static tags as though they were global (implies -h -s)
-s Include static tags
-e Include extern tags
-i Include inline definitions
-t Include typedefs
-v Include variable declarations
-h Add hints to help elvis distinguish between overloaded tags
-l Add a “ln” line number hint (implies -h)
-p Write parse info to stdout (for debugging ctags)
-d Warn about duplicates, on stdout
-x Write cross-reference table to stdout; skip “tags”
-r Write a “refs” file, in addition to “tags”
-a Append to “tags”, instead of overwriting
If no flags are given, ctags assumes it should use -l -i -s -t -v
Report bugs to kirkenda@cs.pdx.edu
what to do ?
April 9th, 2013 at 12:27 pm
Just how do you have the ability to develop a real excellent masses involving commenters to your internet site?