Table of Contents
Tutorial: browsing source code with vim
How to read source code with vim:
- open main.c
- see a function?
- place cursor at the beginning of function name and '#' to search for function definition.
- if function is defined somewhere else:
- open main.c in another window: ':vsplit main.c'
- change to the new window and 'n' or 'N' to search.
- '!grep -ri functionname *'. * Tip: to avoid typing the functionname, you can double click on the function name in the previous step then use 'shift + ins'.
- Tip: to avoid mouse click use 'ctrl + R /' to get the last search term :)).
- open file.c that seems to contain the definition of this function according to output of grep.
- 'n' or 'N' to search inside this file.
Finding fuction definition with ctag and vim
- Install ctags yum install ctags
- Tell vim where to find tagsfile by command in console mode or .vimrc file :set tags=path/to/file, file2 * Create tagsfile in src_dir> pwd ctags -R $(pwd) -o ~/.ctags
- Finding stuffs in vim
Find a tag:
ta: function_name
Find partial name:
ta: /^partname
Back to the last function:
Ctrl + o :ts – shows the list. :tn – goes to the next tag in that list. :tp - goes to the previous tag in that list. :tf – goes to the function which is in the first of the list. :tl – goes to the function which is in the last of the list.