Tutorial: browsing source code with vim

How to read source code with vim:

ctags

Install exuberant ctags

yum install ctags-etags.x86_64

Configure .vimrc

  # search current dir.
  set tags=./tags;    
  let Tlist_Ctags_Cmd='/usr/bin/ctags'
  
On the Wiki
    Wiki Activity
    Random page
    Videos
    Photos
    Chat
Community portal
To do

Contribute Share Watchlist Random page Recent changes Single tags file for a source tree Edit Talk0 1,599pages on this wiki Tip 804 Printable Monobook Previous Next

created 2004 · complexity intermediate · author Dubhead · version 6.0

At the top of a source tree, create a tags file by

% ctags -R

This assumes Exuberant Ctags. The -R (or –recurse) option tells ctags to recurse into directories.

Then, set the tags option in vimrc as:

 set tags=tags;

The last semicolon is the key here. When Vim tries to locate the 'tags' file, it first looks at the current directory, then the parent directory, then the parent of the parent, and so on. This setting works nicely with 'set autochdir', because then Vim's current directory is the same as the directory of the file. If you do not like using 'autochdir' but want the same upward search, use:

 set tags=./tags;

Here, the leading “./” tells Vim to use the directory of the current file rather than Vim's working directory.

Create tag file

ctags -R

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

http://vim.wikia.com/wiki/Browsing_programs_with_tags