ctags with vim editor are very helpful for code walk-through. Navigation is very easy in the large code bases like kernel, where we can jump to
function/identifier definition directly using simple keys.
ctags installation:
=============
ctags can be installed in ubuntu by
sudo apt-get install exuberant-ctags
How to use ctags:
==============
1. Generate tag file for the required code base.
change your current working directory to desired code base directory using cd command.
Now, run below command
ctages -R .
Output: We see "tags" file in the current working directory after successful.
It will store all index information of functions or identifiers in the tag file.
2. Now, open any file in the current working directory using vim editor.
Place cursor on any funtion/identifier.
3. Press ctrl + ] together. We will redirect to the file where this function/identifier is defined.
If there are multiple entries for this definition, we can check one by one by following way
Goto vim's command mode by typing ":" and type tnext (goes to next tag)
4. Once you see the required definition, use ctrl+t to go back to your base point where you did step-3
Note: Instead of step-2, we can use vim’s command mode to jump to function/identifier definition:
:tag function_name
:ta function_name
The below commands will be used to accept regular expressions.
Example, :tag /^asserts_* would find all tags that start with ‘asserts_’.
By default vim will jump to the first result, but a number of commands can be used to sort through the list of tags:
:ts or :tselect shows the list
:tn or :tnext goes to the next tag in that list
:tp or :tprev goes to the previous tag in that list
:tf or :tfirst goes to the first tag of the list
:tl or :tlast goes to the last tag of the list
To show the tags you’ve traversed since you opened vim, run :tags.
For more info on ctags, please check here
function/identifier definition directly using simple keys.
ctags installation:
=============
ctags can be installed in ubuntu by
sudo apt-get install exuberant-ctags
How to use ctags:
==============
1. Generate tag file for the required code base.
change your current working directory to desired code base directory using cd command.
Now, run below command
ctages -R .
Output: We see "tags" file in the current working directory after successful.
It will store all index information of functions or identifiers in the tag file.
2. Now, open any file in the current working directory using vim editor.
Place cursor on any funtion/identifier.
3. Press ctrl + ] together. We will redirect to the file where this function/identifier is defined.
If there are multiple entries for this definition, we can check one by one by following way
Goto vim's command mode by typing ":" and type tnext (goes to next tag)
4. Once you see the required definition, use ctrl+t to go back to your base point where you did step-3
Note: Instead of step-2, we can use vim’s command mode to jump to function/identifier definition:
:tag function_name
:ta function_name
The below commands will be used to accept regular expressions.
Example, :tag /^asserts_* would find all tags that start with ‘asserts_’.
By default vim will jump to the first result, but a number of commands can be used to sort through the list of tags:
:ts or :tselect shows the list
:tn or :tnext goes to the next tag in that list
:tp or :tprev goes to the previous tag in that list
:tf or :tfirst goes to the first tag of the list
:tl or :tlast goes to the last tag of the list
To show the tags you’ve traversed since you opened vim, run :tags.
For more info on ctags, please check here
No comments:
Post a Comment