vim :: tags keyboard shortcuts
Keyboard shortcuts used to work with tags. There are really few of them. All of them work in control/normal mode.
:set tags?
needless to remind that VIM must be told which tag files to use. It can be done automatically as for example shown here.:tag word
is main one. Opens file and goes to line with first tag entry matching word.- ^] same as above, but uses word under cursor.
:tag /word
is similar to:tag word
. Opens file and goes to line with first tag entry matching regular expression in word.:tselect word
is what I use most often. The function - tag select - displays list of matching tags allowing you to select one to go to. Without word, it will display list of matching tags for word used last time.g^]
same as above, but uses word under cursor. Also, omits displaying list if only single match is found.:tnext
goes to next matching tag entry.:tprev
goes to previous matching tag entry.:tlast
goes to last matching tag entry.:tfirst
goes to first matching tag entry.^T
Every time you do:tag word
, the word with current file position is put on stack and vim goes to new file/position as it is told by tag file. To restore the previous file position you use^T
. The shortcut removes tag stack top element and moves to the file position saved there. So if you wandered off far away with^]
- to return back where you started you need to press^T
until vim would complain that it is at bottom of tag stack.
:tag word
and :tselect word
support wildcard key (Tab/^D) to show list of tags matching partially the word. That will work with regilar expressions too. But be warned that often tag files can host millions of entries: displaying list of thousands items can take some time. Use wildcard key carefully.