Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tag navigation in vim

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-])

like image 826
vpillai Avatar asked Jul 22 '13 09:07

vpillai


People also ask

How do I set tags in Vim?

Select tag from tag list. You can select a particular tag from the tag list after opening the file in the vim editor by using ctags command. Open any source code in vim editor and type ':tselect' to find out the list of tag list of current source code. Here, the same file, abs_num.py is used to check this command.

What is tag stack in Vim?

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.


3 Answers

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.

like image 154
romainl Avatar answered Oct 23 '22 21:10

romainl


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.
like image 32
Chetan Potdar Avatar answered Oct 23 '22 22:10

Chetan Potdar


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>

like image 5
Joel Strouts Avatar answered Oct 23 '22 22:10

Joel Strouts