CTags Help

Use vim with ctags

# Some MacOS comes with ctags 
$ /usr/bin/ctags
usage: ctags [-BFadtuwvx] [-f tagsfile] file ...
    
# Don't use that default ctags. Install Exuberant Ctags from homebrew
$ brew install ctags
$ alias ctags="`brew --prefix`/bin/ctags"
$ alias ctags >> ~/.bash_profile
    
$ which ctags
/usr/local/bin/ctags

How to generate tags file?

  • cd to the root directory of your source code
  • Run Ctags recursively over the entire source code to generate the tags file
  • Command to generate tags:
# Example: Source code is in 'openssl' directory
$ cd openssl

$ ctags --recurse=yes --exclude=.git --exclude=BUILD --exclude=.svn --exclude=vendor/* --exclude=node_modules/* --exclude=db/* --exclude=log/*

$ ls -la tags
-rw-r--r-- 1 alice dev 3640065 Jan 24 23:11 tags
Keyboard commandAction
Ctrl + ]
OR
g]
OR
:ta[g] Ctrl+rw
Jump to the tag underneath the cursor using the information in the tags file(s)
:ts[elect] <tag_name> List the tags that match <tag_name>, using the information in the tags file(s). When <tag_name> is not given, the last tag name from the tag stack is used
:pts[elect] <tag_name>                                                               Does :tselect and shows the new tag in a “Preview” window (horizontal split) without moving the cursor
Ctrl + w }
OR
:ptag Ctrl+rw
Opens a preview window with the location of the tag definition. The cursor does not change its position, so tag stack is not updated
Ctrl + wz
OR
:pc
Close preview window created by the command Ctrl+w }
Ctrl + w Ctrl + ] Open the definition in a horizontal split
:tn Jump to next matching tag (If there are multiple matches)
:tp Jump to previous matching tag (If there are multiple matches)
Ctrl-t Jump back up in the tag stack
:tags Show the contents of the tag stack. The active entry is marked with a >

how-to-generate-tags-file

tags help

g]             Like CTRL-], but use ":tselect" instead of ":tag"

tag-prioirity

When there are multiple matches for a tag, this priority is used:
1. "FSC"  A full matching static tag for the current file.
2. "F C"  A full matching global tag for the current file.
3. "F  "  A full matching global tag for another file.
4. "FS "  A full matching static tag for another file.
5. " SC"  An ignore-case matching static tag for the current file.
6. "  C"  An ignore-case matching global tag for the current file.
7. "   "  An ignore-case matching global tag for another file.
8. " S "  An ignore-case matching static tag for another file.

Include file searches

These commands look for a string in the current file and in all encountered included files (recursively).
This can be used to find the definition of a variable, function or macro.
These commands are not available when the +find_in_path feature was disabled at compile time.
The commands that start with "[" start searching from the start of the current file. The commands
that start with "]" start at the current cursor position.

[i            Display the first line that contains the keyword under the cursor. The search starts at the
              beginning of the file. Lines that look like a comment are ignored (see 'comment' option).
              If a count is given, the count'th matching line is diplayed, and comment lines are not ignored.
              
]i            like "[i", but start at the current cursor position.

[I            Display all lines that contain the keyword under the cursor.

]I [ CTRL-I ] CTRL-I

[d            Display the first macro definition that contains the macro under the cursor.
]d [D ]D [ CTRL-D  ] CTRL-D

posted @ 2021-12-28 18:36  anyboo  阅读(30)  评论(0编辑  收藏  举报