Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Opening (c)tags in new tab in (G)Vim

Tags:

vim

Ctrl+w Ctrl+i and :stj is nice, but how do I jump to a tag (under the cursor) in a new tab in GVim/Vim?

like image 247
Walter Avatar asked May 25 '09 22:05

Walter


People also ask

How do I open a new tab in Vim?

Opening a tab Probably the easiest to remember is to run the :tabnew command while in normal mode. This will open a new tab with an empty buffer. If you want to edit a file in the new tab, you can run :tabnew filename and Vim will load the file in the new tab.

How do I use tags in Vim?

To use the tags file, you'll need to open Vim and tell it where it is. Still in the Vim source directory, I ran vim and then typed :set tags+=tags to tell it to use the ./tags file. At this point, Vim knows about the tags file — you don't need to tell it to load the file.

How do I go to a specific tab in Vim?

In gnome-terminal, I can just press Alt + ( 1 , 2 , 3 , etc.) to switch to specific tabs. I can also use Ctrl + ( PgUp / PgDn ) to cycle through tabs (admittedly less convenient, but it can be remapped). If I want to use vim tabs instead of gnome-terminal tabs, typing :tabn and :tabp is quite cumbersome.


2 Answers

Similar question How to use multiple tabs when tagging to a function in Vim

It points out this wiki (which points back at stackoverflow) with these settings (seems to work ok in terminal, haven't tried gvim):

"--------------------
" Function: Open tag under cursor in new tab
" Source:   https://stackoverflow.com/questions/563616/vimctags-tips-and-tricks
"--------------------
map <C-\> :tab split<CR>:exec("tag ".expand("<cword>"))<CR>
"--------------------
" Function: Remap keys to make it more similar to firefox tab functionality
" Purpose:  Because I am familiar with firefox tab functionality
"--------------------
map     <C-T>       :tabnew<CR>
map     <C-N>       :!gvim &<CR><CR>
map     <C-W>       :confirm bdelete<CR>
like image 135
stefanB Avatar answered Oct 05 '22 04:10

stefanB


You can also open tags in preview :ptag with C-w}

like image 38
Xiangpeng Avatar answered Oct 05 '22 04:10

Xiangpeng