Skip to content

Browsing Source Code Efficiently in Vim: ctags

December 9, 2015

I have been using vim for my development for several years. All these while I am settle with my F4 custom function, which will perform recursive search of the source code for a particular symbol, as shown below:

map <F4> :execute “vimgrep /” . expand(“<cword>”) . “/j **/*.c **/*.C **/*.h **/*.H” <Bar> cw<CR>

It works well and I have never further explore for better tools. Until recently there is a need for search of large source code. That’s where I bump into ctags. Ctags will preindex all the symbol. When using it to ‘jump’ to function definition is instant. Founding about this is like one of those moment I told myself – I should have know about this long time ago.

Quick setup of ctags

  1. Package install in ubuntu
    1. apt-get install exuberant-ctags
  2. ‘cd’ to source folder and perform indexing. A file name ‘tags’ will be generated end of this command
    1. ctags -R *
  3. Open any source file, for example
    1. vi ./Source/main.c
  4. ctags shortcut key:
    1. ctrl + ]  : To go to function definition, move the cursor to the function
    2. ctrl + t  : go back to location before performing ‘ctrl+]’

I am sure there have more command, but for now, the above 2 is good enough for me.

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: