How to browse source code using vim+ctags

By default vim can use ctags index file to browse through the source code. To do it, following the instruction below:

  1. Generate the tags index file which will define the location of all the functions and global declarations. This can be done using the ctags application for the required path:
    $ ctags -R ./src
    This command will create the tags index file in the current directory. The src directory will be transversed recursively. All the source files will be parsed. Please refer to the "man ctags" documentation page for more details of how to use ctags.
  2. Run vim from the directory where the tags index file is located. To jump to the required function the "-t" vim option can be used:
    $ vim -t main
    This will jump to the main object declaration, if any.
  3. While browsing the source code the following hot keys can be used to jump through declarations:
    "Ctrl+]" - to jump on object declaration
    "Ctrl+t" - jump back
    Refer to vim help for more details.

For example the following sequence can be used to browse the illumos source code:

  1. Generate index file:
    $ cd /illumos-gate/usr/src
    $ ctags -R ./
  2. Run vim for the function or declaration required:
    $ vim -t _endopen
  3. Browse source code using vim functionality.