How to use multiple tabs when tagging to a function in Vim
Asked Answered
I

3

13

I use ctags with my Vim and I rely heavily on C-] and C-T to tag back and froth between various functions in my project.

But if the function is in a different file, I'd like Vim to automatically open it in a new tab instead of the current tab. If I pop my tag stack using the C-T, I'd like it go back to the original tab where I pressed by C-] instead of changing the file in the current tab. I don't like to have the same file opened in multiple tabs in Vim. This is the normal behavior for most IDEs and I am wondering if there is a way to do this in Vim?

Ironist answered 11/2, 2009 at 22:50 Comment(0)
A
12
nmap <C-Enter> <C-w><C-]><C-w>T

Does this help ? You could probably figure out something similar for the way back.


Well, we need to decide what would be the wanted behaviour. We can go back to the original tab (not sure how, still investigating) but then the above given mapping is gonna open a new tab next time. So you'll end up with a lot of tabs after a while.

Or we can do <C-w>C, which will close the opened tab and take us back to the original one. I, personally, prefer this way of working (that way I don't lose my position in the file) I go to the function I want, make my corrections there then return to the original file from which I started. Let me know, what would you like (this didn't fit in comments so I put the answer here).

Agoraphobia answered 11/2, 2009 at 23:35 Comment(5)
Coming back using the C-T is the hard part. I can't seem to think of any way where I can press C-T and it takes me back to the original tab where I came from.Ironist
Is there a way to do this and still use C-] as the shortcut?Slipsheet
No but it appears as if a new mapping is being defined here for C-Enter. I wanted to know if C-] can be remapped to <C-w><C-]><C-w>T.Slipsheet
@Slipsheet - You can remap anything. Just change it in the mapping to whatever you find best.Agoraphobia
mapping <C-Enter> didn't work for me, (pressing <C-Enter> has the same result as Enter)Speedometer
A
5

This might point you in the right direction:

http://vim.wikia.com/wiki/Open_every_buffer_in_its_own_tabpage

Annecy answered 11/2, 2009 at 23:19 Comment(0)
B
0

So, this is a feature I would like to see as well.

I'm not sure if it's possible.

What I usually do is

:tabnew :tag somepartsoffunction*

and press tab to use globbing to easily find tag.

Sure, it's not an ideal solution, but it works most of the time.

Unfortunately, with VIM tabbing isn't totally integrated since it's a new feature since 7.0. Most people I know that use VIM weren't even aware of tabs until I told them, so with that, I have a feeling there is no way to do it right now.

(I would love to be proven wrong)

Brierwood answered 11/2, 2009 at 23:4 Comment(1)
It's not that "tabbing isn't totally integrated", but that the tabline isn't meant to be a replacement for :ls. Vim's tabs aren't supposed to works like tabs in other editors--they are just so you can have different window layouts.Bouffant

© 2022 - 2024 — McMap. All rights reserved.