Using ctags and Vim is a lethal combination, especially when doing bigger projects.

Using them gives you the following features:

  • Impressive class/function/method search
  • Ability to go to the definition of a function with one click (even in dynamic languages like Python)
  • Better overview by a module browser (where you can see classes and members)

Getting started with Taglist

Tag list opens a left window where you can browse the current file. It gives a nice overview. Here is an example (click for a bigger picture):

taglist_small

First download ctags. On Debian/Ubuntu it would be:

sudo apt-get install exuberant-ctags

After this, install the taglist.vim plugin, you can get it here.

Now you need to configure taglist.vim, this can be done like this:

let Tlist_Ctags_Cmd = "/usr/bin/ctags"
let Tlist_WinWidth = 50
map <F4> :TlistToggle<cr>

Pressing F4 will toggle the taglist window on and off. Try it out, it's really useful :)

For more options look in taglist.txt documentation, it comes when downloading taglist.vim.

Search and destroy using tags

I have one mapping in vimrc:

map <F8> :!/usr/bin/ctags -R --c++-kinds=+p --fields=+iaS --extra=+q .<CR>

This builds tags libs for the current working directory (it's super fast).

Once you have build tags, you can browse them using builtin functions. Here are some examples:

  • :tag getUser => Jump to getUser method
  • :tn (or tnext) => go to next search result
  • :tp (or tprev) => to to previous search result
  • :ts (or tselect) => List the current tags
  • => Go back to last tag location
  • +Left click => Go to definition of a method

If you want full power out of this I recommend reading following documentation:

  • http://vimdoc.sourceforge.net/htmldoc/tagsrch.html (official documentation)
  • http://www.vim.org/tips/tip.php?tip_id=94 (a vim tip)

----------------------------------------------------------------------------------------------------------------------

自动补全括号与引号(加入.vimrc中)

  1. inoremap ( ()<ESC>i  
  2. inoremap ) <c-r>=ClosePair(')')<CR>  
  3. inoremap { {}<ESC>i  
  4. inoremap } <c-r>=ClosePair('}')<CR>  
  5. inoremap [ []<ESC>i  
  6. inoremap ] <c-r>=ClosePair(']')<CR>  
  7. inoremap < <><ESC>i  
  8. inoremap > <c-r>=ClosePair('>')<CR>  
  9. :inoremap " ""<ESC>i   
  10. :inoremap ' ''<ESC>i  
  11.  
  12. function ClosePair(char)  
  13.     if getline('.')[col('.') - 1] == a:char  
  14.         return "\<Right>"  
  15.     else  
  16.         return a:char  
  17.     endif  
  18. endf 
此文章由 flyinweb 于 2010-07-29 11:54:29 编辑

本日志由 flyinweb 于 2010-07-29 11:46:40 发表,目前已经被浏览 3952 次,评论 0 次;

作者添加了以下标签: Vimctagstaglist

引用通告:http://www.517sou.net/Article/501/Trackback.ashx

评论订阅:http://www.517sou.net/Article/501/Feeds.ashx

评论列表

    暂时没有评论
(必填)
(必填,不会被公开)