Code reading with Ctags and Vim

From Akionux-wiki
Share/Save/Bookmark
Jump to: navigation, search

Abstract

Ctags is useful code reading tool. Here, search a class or function from source codes in Vim[1].

Steps

Go to path of source and run ctags -R :

cd ~/path/to/source
ctags -R

Now, 'tag' is created in the current directory.

To read the tag file when vim starts, edit .vimrc :

vim ~/.vimrc

Add following lines :

" ctags
set tags=./tags,~/path/to/source/tags

Then start vim. If you want to find out a class or function under the cursor, press Ctrl+] and jump to the position in which the class or function is defined.

Tips to use ctags with vim[1]:

  • If there are two or more candidates, press g, Ctrl+] and choose the destination to jump.
  • Go back to previous position, press Ctrl+t or Ctrl+o, or run :pop.
  • Press C-w} to open preview window.
  • Press C-wC-z or :pc to close the preview window.
  • Run :tags to check the destination before jumping.

References