Tag navigation in vim
Asked Answered
S

3

11

With cscope integrated Vim, I can navigate back using the ctrl-T and see the current tag stack position using :tags . But how do I go forward in the stack? The only thing I could find from the man pages is to go to the function definition (like ctrl-])

Sedgewinn answered 22/7, 2013 at 9:4 Comment(1)
@Kent I am not using ctags as-suck. I am using ctags. So :ta is not wirkingSedgewinn
D
13

The tag stack is created by all your "jump to definition". Each time you do <C-]>, the tag you jump to is added to the tag stack and you are able to use <C-t> or :pop to jump back to the previous tag in the tag stack or :tag to go the other way. Both :tag and :pop take an optional count so :5pop would go to the fifth previous tag.

See :help tagstack.

Deposition answered 22/7, 2013 at 18:48 Comment(0)
I
27

You can also use Ctrl+I and Ctrl+O to move forwards and backwards respectively through the jump list. This works with tag commands since they count as jump movements.

So to:

  • Jump to a tag: Ctrl+].
  • Jump back: Ctrl+O.
  • Jump to a tag again: Ctrl+I.
Index answered 22/7, 2013 at 9:8 Comment(1)
That works in the jump list (and tag list as a side effect). But they are not exactly tag navigation.Sedgewinn
D
13

The tag stack is created by all your "jump to definition". Each time you do <C-]>, the tag you jump to is added to the tag stack and you are able to use <C-t> or :pop to jump back to the previous tag in the tag stack or :tag to go the other way. Both :tag and :pop take an optional count so :5pop would go to the fifth previous tag.

See :help tagstack.

Deposition answered 22/7, 2013 at 18:48 Comment(0)
R
6

Just adding this answer because I don't have the rep to edit or comment on the accepted answer, but <C-t> actually corresponds to the :pop command, not the :tag command as was stated.

:pop is for moving "backwards" in the tag stack (will result in 'at bottom of tag stack' message) and is the command with the default keybinding <C-t>

:tag is for moving "forwards" in the tag stack (will result in 'at top of tag stack' message).

I am not aware of any keybinding for :tag like for moving backwards, so I have mapped (not ) to tag.

nnoremap <C-[> :tag<CR>

Reclamation answered 27/8, 2017 at 1:22 Comment(1)
I've edited the accepted answer. Surprised it was left so long!Rosalbarosalee

© 2022 - 2024 — McMap. All rights reserved.