vim with ctags
December 10th, 2006 mysurface Posted in Developer, ctags, ln, vi, vim | Hits: 10278 |
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.
Live Chat!









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.