Nvim :help
pages, generated
from source
using the tree-sitter-vimdoc parser.
tag
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.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.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
E426
E429
:[count]ta[g][!] {name}
Jump to the definition of {name}
, using the
information in the tags file(s). Put {name}
in the
tag stack. See tag-! for [!].
{name}
can be a regexp pattern, see tag-regexp.
When there are several matching tags for {name}
, jump
to the [count] one. When [count] is omitted the
first one is jumped to. See tag-matchlist for
jumping to other matching tags.g<LeftMouse>
<C-LeftMouse>
<C-LeftMouse>
CTRL-]
CTRL-]
Jump to the definition of the keyword under the
cursor. Same as ":tag {name}
", where {name}
is the
keyword under or after cursor.
When there are several matching tags for {name}
, jump
to the [count] one. When no [count] is given the
first one is jumped to. See tag-matchlist for
jumping to other matching tags.telnet-CTRL-]
CTRL-]
is the default telnet escape key. When you type CTRL-]
to jump to a
tag, you will get the telnet prompt instead. Most versions of telnet allow
changing or disabling the default escape key. See the telnet man page. You
can telnet -E {Hostname}
to disable the escape character, or
telnet -e {EscapeCharacter} {Hostname}
to specify another escape character.
If possible, try to use "ssh" instead of "telnet" to avoid this problem.tag-priority
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.{name}
".g<RightMouse>
<C-RightMouse>
<C-RightMouse>
CTRL-T
CTRL-T Jump to [count] older entry in the tag stack
(default 1).:po
:pop
E555
E556
:[count]po[p][!] Jump to [count] older entry in tag stack (default 1).
See tag-! for [!].:tags
:tags Show the contents of the tag stack. The active
entry is marked with a '>'.CTRL-T
and ":pop" command will use the position
above the active entry.CTRL-T
to position before previous tag
{count}
CTRL-T
to position before {count}
older tag
":tag" to newer tag
":0tag" to last used tagCTRL-]
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.{name}
" 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:tagstack-examples
Write to the tag stack just like :tag
but with a user-defined
jumper#jump_to_tag function:" Store where we're jumping from before we jump. let tag = expand('<cword>') let pos = [bufnr()] + getcurpos()[1:] let item = {'bufnr': pos[0], 'from': pos, 'tagname': tag} if jumper#jump_to_tag(tag) " Jump was successful, write previous location to tag stack. let winid = win_getid() let stack = gettagstack(winid) let stack['items'] = [item] call settagstack(winid, stack, 't') endif
call settagstack(1005, {'curidx' : 4})
let pos = [bufnr('myfile.txt'), 10, 1, 0] let newtag = [{'tagname' : 'mytag', 'from' : pos}] call settagstack(2, {'items' : newtag}, 'a')
E73
When you try to use the tag stack while it doesn't contain anything you will
get an error message.:ts
:tselect
:ts[elect][!] [name] List the tags that match [name], using the
information in the tags file(s).
When [name] is not given, the last tag name from the
tag stack is used.
See tag-! for [!].
With a '>' in the first column is indicated which is
the current position in the list (if there is one).
[name] can be a regexp pattern, see tag-regexp.
See tag-priority for the priorities used in the
listing.
Example output:# pri kind tag file 1 F f mch_delay os_amiga.c mch_delay(msec, ignoreinput) > 2 F f mch_delay os_msdos.c mch_delay(msec, ignoreinput) 3 F f mch_delay os_unix.c mch_delay(msec, ignoreinput) Type number and <Enter> (empty cancels):
:sts
:stselect
:sts[elect][!] [name] Does ":tselect[!] [name]" and splits the window for
the selected tag.g]
g] Like CTRL-]
, but use ":tselect" instead of ":tag".v_g]
{Visual}
g] Same as "g]", but use the highlighted text as the
identifier.:tj
:tjump
:tj[ump][!] [name] Like ":tselect", but jump to the tag directly when
there is only one match.:stj
:stjump
:stj[ump][!] [name] Does ":tjump[!] [name]" and splits the window for the
selected tag.:tp
:tprevious
:[count]tp[revious][!] Jump to [count] previous matching tag (default 1).
See tag-! for [!].:tr
:trewind
:[count]tr[ewind][!] Jump to first matching tag. If [count] is given, jump
to [count]th matching tag. See tag-! for [!].:lt
:ltag
:lt[ag][!] [name] Jump to tag [name] and add the matching tags to a new
location list for the current window. [name] can be
a regexp pattern, see tag-regexp. When [name] is
not given, the last tag name from the tag stack is
used. The search pattern to locate the tag line is
prefixed with "\V" to escape all the special
characters (very nomagic). The location list showing
the matching tags is independent of the tag stack.
See tag-! for [!].tag 1 of 3 or moreThe " or more" is used to indicate that Vim didn't try all the tags files yet. When using ":tnext" a few times, or with ":tlast", more matches may be found.
:0tn
tag-skip-file
When a matching tag is found for which the file doesn't exist, this match is
skipped and the next matching tag is used. Vim reports this, to notify you of
missing files. When the end of the list of matches has been reached, an error
message is given.tag-preview
The tag match list can also be used in the preview window. The commands are
the same as above, with a "p" prepended.:pts
:ptselect
:pts[elect][!] [name] Does ":tselect[!] [name]" and shows the new tag in a
"Preview" window. See :ptag for more info.:ptj
:ptjump
:ptj[ump][!] [name] Does ":tjump[!] [name]" and shows the new tag in a
"Preview" window. See :ptag for more info.static-tag
A static tag is a tag that is defined for a specific file. In a C program
this could be a static function.tag-binary-search
Vim uses binary searching in the tags file to find the desired tag quickly.
But this only works if the tags file was sorted on ASCII byte value.
Therefore, if no match was found, another try is done with a linear search.
If you only want the linear search, reset the 'tagbsearch' option. Or better:
Sort the tags file!tag-regexp
The ":tag" and ":tselect" commands accept a regular expression argument. See
pattern for the special characters that can be used.
When the argument starts with '/', it is used as a pattern. If the argument
does not start with '/', it is taken literally, as a full tag name.
Examples::tag main
:tag /^get
:tag /norm
tag-!
If the tag is in the current file this will always work. Otherwise the
performed actions depend on whether the current file was changed, whether a !
is added to the command and on the 'autowrite' and 'winfixbuf' options:tag-security
Note that Vim forbids some commands, for security reasons. This works like
using the 'secure' option for exrc/vimrc files in the current directory. See
trojan-horse and sandbox.
When the {tagaddress}
changes a buffer, you will get a warning message:
"WARNING: tag command changed a buffer!!!"
In a future version changing the buffer will be impossible. All this for
security reasons: Somebody might hide a nasty command in the tags file, which
would otherwise go unnoticed. Example::$d|/tag-function-name/In Vi the ":tag" command sets the last search pattern when the tag is searched for. In Vim this is not done, the previous search pattern is still remembered, unless the 't' flag is present in 'cpoptions'.
tags-option
The 'tags' option is a list of file names. Each of these files is searched
for the tag. This can be used to use a different tags file than the default
file "tags". It can also be used to access a common tags file.:set tags=./tags,tags,/home/user/commontagsIn this example the tag will first be searched for in the file "tags" in the directory where the current file is. Next the "tags" file in the current directory. If it is not found there, then the file "/home/user/commontags" will be searched for the tag.
:set tags=tags\ /home/user/commontagsTo include a space in a file name use three backslashes. To include a comma in a file name use two backslashes. For example, use:
:set tags=tag\\\ file,/home/user/common\\,tagsfor the files "tag file" and "/home/user/common,tags". The 'tags' option will have the value "tag\ file,/home/user/common\,tags".
ctags
jtags
A tags file can be created with an external command, for example "ctags". It
will contain a tag for each function. Some versions of "ctags" will also make
a tag for each "#defined" macro, typedefs, enums, etc.Exuberant_ctags
exuberant ctags Works for C, C++, Java, Fortran, Eiffel and others.
See https://ctags.sourceforge.net. No new version
since 2009.
JTags For Java, in Java. It can be found at
https://www.fleiner.com/jtags/.
ptags.py For Python, in Python. Found in your Python source
directory at Tools/scripts/ptags.py.{tagname}
{TAB}
{tagfile}
{TAB}
{tagaddress}
2. {tagname}
{TAB}
{tagfile}
{TAB}
{tagaddress}
{term}
{field}
..<NL>
or <CR>
<NL>
. On the Macintosh <CR>
also works. The <CR>
and <NL>
characters can never appear inside a line.{tagname}
The identifier. Normally the name of a function, but it can
be any identifier. It cannot contain a <Tab>
.
{TAB}
One <Tab>
character. Note: previous versions allowed any
white space here. This has been abandoned to allow spaces in
{tagfile}
.
{tagfile}
The file that contains the definition of {tagname}
. It can
have an absolute or relative path. It may contain environment
variables and wildcards (although the use of wildcards is
doubtful). It cannot contain a <Tab>
.
{tagaddress}
The Ex command that positions the cursor on the tag. It can
be any Ex command, although restrictions apply (see
tag-security). Posix only allows line numbers and search
commands, which are mostly used.
{term}
;" The two characters semicolon and double quote. This is
interpreted by Vi as the start of a comment, which makes the
following be ignored. This is for backwards compatibility
with Vi, it ignores the following fields. Example:APP file /^static int APP;$/;" v
{tagaddress}
is not a line number or search pattern, then
{term}
must be |;"
. Here the bar ends the command (excluding
the bar) and ;"
is used to have Vi ignore the rest of the
line. Example:APP file.c call cursor(3, 4)|;" v
{field}
.. A list of optional fields. Each field has the form:<Tab>
{fieldname}
:{value}{fieldname}
identifies the field, and can only contain
alphabetical characters [a-zA-Z].
The {value}
is any string, but cannot contain a <Tab>
.
These characters are special:
"\t" stands for a <Tab>
"\r" stands for a <CR>
"\n" stands for a <NL>
"\\" stands for a single '\' characterctags --list-kinds
.tag-search
The command can be any Ex command, but often it is a search command.
Examples:
<EOL>
).
See pattern. Note that you must put a backslash before each backslash in
the search text. This is for backwards compatibility with Vi.E434
E435
If the command is a normal search command (it starts and ends with "/" or
"?"), some special handling is done:
"^tagname[ \t]*("
"^[#a-zA-Z_].*\<tagname[ \t]*("
tag-old-static
Until March 2019 (patch 8.1.1092) an outdated format was supported:
{tagfile}
:{tagname} {TAB}
{tagfile}
{TAB}
{tagaddress}
{tagfile}
. Note that for the static tag,
the two occurrences of {tagfile}
must be exactly the same. Also see
tags-option below, for how static tags are used."^# *define"
it is not considered to be a comment.:map <F4> [I:let nr = input("Which one: ")<Bar>exe "normal " .. nr .. "[\t"<CR>
[i
[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 'comments' option). If a count is given,
the count'th matching line is displayed, and comment
lines are not ignored.]i
]i like "[i", but start at the current cursor position.:is
:isearch
:[range]is[earch][!] [count] [/]pattern[/]
Like "[i" and "]i", but search in [range] lines
(default: whole file).
See :search-args for [/] and [!].[I
[I Display all lines that contain the keyword under the
cursor. Filenames and line numbers are displayed
for the found lines. The search starts at the
beginning of the file.]I
]I like "[I", but start at the current cursor position.:il
:ilist
:[range]il[ist][!] [/]pattern[/]
Like "[I" and "]I", but search in [range] lines
(default: whole file).
See :search-args for [/] and [!].[_CTRL-I
[ CTRL-I
Jump to 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 'comments' option). If a count is given,
the count'th matching line is jumped to, and comment
lines are not ignored.:ij
:ijump
:[range]ij[ump][!] [count] [/]pattern[/]
Like "[ CTRL-I
" and "] CTRL-I
", but search in
[range] lines (default: whole file).
See :search-args for [/] and [!].CTRL-I
CTRL-W_CTRL-I
CTRL-W_i
CTRL-W i Open a new window, with the cursor on 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 line are ignored (see
'comments' option). If a count is given, the count'th
matching line is jumped to, and comment lines are not
ignored.:isp
:isplit
:[range]isp[lit][!] [count] [/]pattern[/]
Like "CTRL-W i" and "CTRL-W i", but search in
[range] lines (default: whole file).
See :search-args for [/] and [!].[d
[d Display the first macro definition that contains the
macro under the cursor. The search starts from the
beginning of the file. If a count is given, the
count'th matching line is displayed.[d-default
Jumps to the previous diagnostic in the current buffer
by default. vim.diagnostic.jump() default-mappings]d
]d like "[d", but start at the current cursor position.]d-default
Jumps to the next diagnostic in the current buffer by
default. vim.diagnostic.jump() default-mappings:ds
:dsearch
:[range]ds[earch][!] [count] [/]string[/]
Like "[d" and "]d", but search in [range] lines
(default: whole file).
See :search-args for [/] and [!].[D
[D Display all macro definitions that contain the macro
under the cursor. Filenames and line numbers are
displayed for the found lines. The search starts
from the beginning of the file.[D-default
Jumps to the first diagnostic in the current buffer by
default. vim.diagnostic.jump() default-mappings]D
]D like "[D", but start at the current cursor position.]D-default
Jumps to the last diagnostic in the current buffer by
default. vim.diagnostic.jump() default-mappings:dli
:dlist
:[range]dli[st][!] [/]string[/]
Like [D
and ]D
, but search in [range] lines
(default: whole file).
See :search-args for [/] and [!].
Note that :dl
works like :delete
with the "l"
flag, not :dlist
.[_CTRL-D
[ CTRL-D
Jump to the first macro definition that contains the
keyword under the cursor. The search starts from
the beginning of the file. If a count is given, the
count'th matching line is jumped to.:dj
:djump
:[range]dj[ump][!] [count] [/]string[/]
Like "[ CTRL-D
" and "] CTRL-D
", but search in
[range] lines (default: whole file).
See :search-args for [/] and [!].CTRL-D
CTRL-W_CTRL-D
CTRL-W_d
CTRL-W d Open a new window, with the cursor on the first
macro definition line that contains the keyword
under the cursor. The search starts from the
beginning of the file. If a count is given, the
count'th matching line is jumped to.:dsp
:dsplit
:[range]dsp[lit][!] [count] [/]string[/]
Like "CTRL-W d", but search in [range] lines
(default: whole file).
See :search-args for [/] and [!].:checkp
:checkpath
:checkp[ath] List all the included files that could not be found.:search-args
Common arguments for the commands above:
[!] When included, find matches in lines that are recognized as comments.
When excluded, a match is ignored when the line is recognized as a
comment (according to 'comments'), or the match is in a C comment
(after "//" or inside /* */
). Note that a match may be missed if a
line is recognized as a comment, but the comment ends halfway the line.
And if the line is a comment, but it is not recognized (according to
'comments') a match may be found in it anyway. Example:/* comment foobar */
:isearch /string/ | echo "the last one"
t
).
'r' The first argument to tagfunc should be interpreted as a
pattern (see tag-regexp), such as when using::tag /pat
E987
The function should return a List of Dict entries. Each Dict must at least
include the following entries and each value must be a string:
name Name of the tag.
filename Name of the file where the tag is defined. It is
either relative to the current directory or a full path.
cmd Ex command used to locate the tag in the file. This
can be either an Ex search pattern or a line number.
Note that the format is similar to that of taglist(), which makes it possible
to use its output to generate the result.
The following fields are optional:
kind Type of the tag.
user_data String of custom data stored in the tag stack which
can be used to disambiguate tags between operations.E986
It is not allowed to close a window or change window from inside 'tagfunc'.
E1299
function TagFunc(pattern, flags, info) function CompareFilenames(item1, item2) let f1 = a:item1['filename'] let f2 = a:item2['filename'] return f1 >=# f2 ? \ -1 : f1 <=# f2 ? 1 : 0 endfunction let result = taglist(a:pattern) call sort(result, "CompareFilenames") return result endfunc set tagfunc=TagFunc