amin
amin

Reputation: 3852

How to jump next tag in current buffer - vim?

Is there a way to jump to next tag in current buffer?

sub A { 
  /* ... */
  [cursor]
}

sub B { /* ... */ }

I know both A and B are tags in current buffer. Is there a way to jump to the next tag after [cursor]? (it would be B in this example).

Upvotes: 2

Views: 168

Answers (1)

Ingo Karkat
Ingo Karkat

Reputation: 172520

There's nothing built-in, but you could implement this yourself:

You can obtain the list of all tags within the current buffer via

:let tags = filter(taglist('.*'), 'v:val.filename ==# expand("%:p")')

Then escape the tag names for use in a regular expression and join them as alternative search branches:

:let tagsExpr = '\V' . join(map(tags, 'escape(v:val.name, "\\")'), '\|')

Finally perform a search to locate the next tag in the current buffer:

:call search(tagsExpr)

Upvotes: 2

Related Questions