Quick links: help overview · quick reference · reference manual toc · command index

tagsearch.txt For Vim version 5.6.  Last change: 1999 Aug 09


                  VIM REFERENCE MANUAL    by Bram Moolenaar


Tags and special searches                               tags-and-searches

1. Jump to a tag                tag-commands
2. Tag stack                    tag-stack

==============================================================================
1. Jump to a tag                                        tag-commands

                                                        tags
A tag is an identifier that appears in a "tags" file.  It is a sort of label
that can be jumped to.  For example: In C programs each function name can be
used as a tag.  The "tags" file has to be generated by a program like ctags,
before the tag commands can be used.

With the ":tag" command the cursor will be positioned on the tag.  With the
CTRL-] command, the keyword on which the cursor is standing is used as the
tag.  If the cursor is not on a keyword, the first keyword to the right of the
cursor is used.

The ":tag" command works very well for C programs.  If you see a call to a
function and wonder what that function does, position the cursor inside of the
function name and hit CTRL-].  This will bring you to the function definition.
An easy way back is with the CTRL-T command.  Also read about the tag stack
below.

                                                        :ta :tag
:ta[g] {ident}          Jump to the definition of {ident}, using the
                        information in the tags file(s).  Put {ident} in the
                        tag stack.
                        {ident} can be a regexp pattern, see tag-regexp.

CTRL-]                  Same as ":tag {ident}", where {ident} is the keyword
                        under or after cursor.  {Vi: identifier after the
                        cursor}

                                                        v_CTRL-]
{Visual}CTRL-]          Same as ":tag {ident}", where {ident} is the text that
                        is highlighted.  {not in Vi}


==============================================================================
2. Tag stack                                            tag-stack tagstack

On the tag stack is remembered which tags you jumped to, and from where.

                                                        CTRL-T
CTRL-T                  Jump to [count] older entry in the tag stack
                        (default 1).  {not in Vi}

                                                        :po :pop
:[count]po[p]           Jump to [count] older entry in tag stack (default 1).
                        {not in Vi}

:[count]ta[g]           Jump to [count] newer entry in tag stack (default 1).
                        {not in Vi}

                                                        :tags
:tags                   Show the contents of the tag stack.  The active
                        entry is marked with a '>'.  {not in Vi}

The output of ":tags" looks like this:

   # TO tag      FROM line in file/line
   1 main                1  harddisk2:text/vim/test
 > 2 FuncA              58  i = FuncA(10);
   3 FuncC             357  harddisk2:text/vim/src/amiga.c

This list shows the tags that you jumped to and the cursor position before
that jump.  The older tags are at the top, the newer at the bottom.

The '>' points to the active entry.  This is the tag that will be used by the
next ":tag" command.  The CTRL-T and ":pop" command will use the position
above the active entry.

Below the "TO" is the number of the current match in the match list.  Note
that this doesn't change when using ":pop" or ":tag".

The line number and file name are remembered to be able to get back to where
you were before the tag command.  The line number will be correct, also when
deleting/inserting lines, unless this was done by another program (e.g.
another instance of Vim).

For the current file, the "file/line" column shows the text at the position.
An indent is removed and a long line is truncated to fit in the window.

You can jump to previously used tags with several commands.  Some examples:

        ":pop" or CTRL-T        to position before previous tag
        {count}CTRL-T           to position before {count} older tag
        ":tag"                  to newer tag
        ":0tag"                 to last used tag

The most obvious way to use this is while browsing through the call graph of
a program.  Consider the following call graph:

        main  --->  FuncA  --->  FuncC
              --->  FuncB

(Explanation: main calls FuncA and FuncB; FuncA calls FuncC).
You can get from main to FuncA by using CTRL-] on the call to FuncA.  Then
you can CTRL-] to get to FuncC.  If you now want to go back to main you can
use CTRL-T twice.  Then you can CTRL-] to FuncB.

If you issue a ":ta {ident}" or CTRL-] command, this tag is inserted at the
current position in the stack.  If the stack was full (it can hold up to 20
entries), the oldest entry is deleted and the older entries shift one
position up (their index number is decremented by one).  If the last used
entry was not at the bottom, the entries below the last used one are
deleted.  This means that an old branch in the call graph is lost.  After the
commands explained above the tag stack will look like this:

   # TO tag     FROM line in file
   1 main               1  harddisk2:text/vim/test
   2 FuncB             59  harddisk2:text/vim/src/main.c
 

 vim:tw=78:ts=8:sw=8:noet:


Quick links: help overview · quick reference · reference manual toc · command index