La Vita è Bella

Wednesday, April 25, 2007

Vim Tip: vim and ctags

If you use vim for programming, then you can't live without ctags (can you?). ctags generate the "tags" file, vim and its plugins use this file to help your programming more efficiently.

By default, vim will only use the "tags" file under your current working directory. You can use this command to see it:

:set tags?

Generally, your "tags" file under you current working directory won't contain informations about system libraries (glibc, stl, etc.). If you miss them, you can generate tags file for your system libraries, and ask your vim to load them:

set tags+=/usr/local/include/tags
set tags+=/usr/include/tags

If you are working on a big project, which have many subdirectories, the "tags" file under each working directory may be not enough, as you also need some information about the functions under other subdirectories. So you can generate a "tags" file under your project root, and ask vim to load it when editing a file within your project:

autocmd BufEnter ~/work/myproj/* :setlocal tags+=~/work/myproj/tags

Thanks for Ryan Phillips, you can also add "tags;" (notice the semicolon) to your tags so that vim will automatically look up "tags" file in the file tree (":help file-searching" for document):

set tags+=tags;

To make it easier to use, I've also made a script named "projtags.vim" so that you need only set your project directories in your vimrc:

let g:ProjTags = ["~/work/proj1"]
let g:ProjTags+= [["~/work/proj2", "~/work/proj2.tags"]]

Happy vimming :P



tags: , , ,

02:37:29 by fishy - dev - Permanent Link

Revision: 1.4/1.4, last modified on 2007-04-26 @ 00:43.

Karma: 42 (61.54% out of 182 were positive) [+/-]

You can subscribe to RSS 2.0 feed for comments and trackbacks

Trackbacks:
La Vita è Bella
More tips about my projtags.vim: I wrote a vim plugin named projtags, initially for loading tags file for projects. But as I can "set tags+=tags;" in my vimrc, it's not that useful on the tags file way. I expanded its...
2010-03- 2 @ 19:58
Use this TrackBack url to ping this item (right-click, copy link target). If your blog does not support Trackbacks you can manually add your trackback by using this form.

Ryan Phillips

Ryan Phillips wrote:

A slick feature (that I don't think is documented) allows you to:

set tags=tags;

The semicolon looks up the file tree for the tags file.

Wednesday, April 25, 2007 11:13:49

fishy

fishy wrote:

Wow, this is a great tip. Thank you, Ryan!

Wednesday, April 25, 2007 12:12:58

mathieu Elie

mathieu Elie wrote:

really cool tips! linking to it.

Tuesday, March 03, 2009 02:50:25

Isaac McGowan

Isaac McGowan wrote:

I love the projtag.vim plugin. What a nice structured way to set tags transparently for entire projects. Thank you!

Saturday, February 25, 2012 01:03:49

Add Comment

 

May the Force be with you. RAmen