We have to generate a file named 'tags' for all the source code files, use the following command:
ctags *.c *.h
Just give the following command to recursively add all files in your project.$ cd /proj
$ ctags -R *
using ctags with VIM editor We have 3 different ways to use ctags in VIM editor. From Shell: We can invoke directly the file or the files containing the definition for a particular function from shell.vi -t function_nameThis will find the correct file or list of files having function_name definition. OR VIM command line: We can invoke from VIM commandline (in command mode) the definition of a function.:tag function_name or :ta function_nameThis will jump automatically from the current file to the file containing the function_name definition. OR By cursor position: This option is more user-friendly as we use a key combination instead of giving commands.
ctrl + ]
Place the cursor on the first character of the function name and press
ctrl-].
This will jump to the file containing the definition of function_name.
ctrl + t
This command will jump back to previous location.
ctrl + i
To travel forward through the tag history.
ctrl + o
To travel backward through the tag history. History To display the list of tags that we have traversed in past give the following command.
:tags
Shows tag stack (history).
Divide and Conquer
As we saw already 'ctrl + ]' replaces the file in the current window with the one containing the new function. But suppose if we want to see not only the old function but also the new one?
We can split the window using the ":split" command followed by the ":tag" command.
:stag function_name
Cursor command for above feature is
ctrl + w + ]
Auto Complete
VIM supports tag name completion. Start typing the tag name (i.e. function name) and then hit TAB key and name completion will be done automatically
if there is a tag name.
:tag start-of-tag-name_TAB
Jump to a tag name found by a search.
:tag /search-string
When multiple entries exist in the tags file, such as a function declaration in a header file and a function definition (the function itself), the operator can choose by issuing this command. The user will be presented with all the references to the function and the user will be prompted to enter the number associated with the appropriate one.
:tselect function-name
Jumps to next matching tag.
:tnext or :tn
Jump to previous matching tag.
:tprevious or :tp
Jump to first matching tag.
:tfirst or :tf or :trewind or :tr
Jump to last matching tag.
:tlast or :tl
Finding global identifiers
You are editing a C program and wonder if a variable is declared as "int" or "unsigned".
A quick way to find this is with the "[I" command. Suppose the cursor is on the word "column" then type
[ + shiftkey + i
Vim will list the matching lines it can find. Not only in the current file,
but also in all included files (and files included in them, etc.).
No comments:
Post a Comment