ctags - generate tag files for source code

Basic usage:

  1. Install ctags using pacman (on Arch)

  2. Enter the root directory of the source code, and generate tags by running

    ctags -R
    
  3. In vim, locate the cursor on variable or function names, then

    • use Ctrl+] to jump to the definition (push into the tag stack)

    • use Ctrl+T to jump back (pull from the stack)

Generate tags for C and C++ standard library (for Arch only):

  1. Setup a folder ~/.vim/ctags

  2. Run in ~/.vim/ctags

    pacman -Ql glibc | awk '/\/usr\/include/{print $2}' > c_headers
    ctags -L c_headers --c-kinds=+p --fields=+iaS --extra=+q -f c
    pacman -Ql gcc | awk '/\/usr\/include/{print $2}' > c++_headers
    ctags -L c++_headers --c++-kinds=+p --fields=+iaS --extra=+q -f c++
    
  3. Add the following lines in .vimrc

    set tags+=~/.vim/ctags/c
    set tags+=~/.vim/ctags/c++
    

cscope - interactively examine a C program

Basic usage:

  1. Install cscope using pacman (on Arch)

  2. Enter the root directory of the source code, and generate cscope database by running

    cscope -Rb
    

    Note.

    1. For operating system or C/C++ standard library development, use

      cscope -Rbk
      
    2. For lookup accleration, use

      cscope -Rbq
      
  3. In vim, first run

    :cs add cscope.out
    

    Then you can use various cscope commands. To see help, run

    :cs
    

You may also have interest in this toturial http://cscope.sourceforge.net/cscope_vim_tutorial.html