7

I'm familiar with ngT, which will move n tabs backward. Is there an equivalent way to move forward? I know that if I have 5 tabs open and I'm on tab 3, I can use 3gT to move backwards to tab 5. However, this quickly becomes unwieldy as the number of tabs increases and I lose track of the exact number I'm on at a given time.

Floegipoky
  • 457
  • 5
  • 13
  • I am a bit worried that you using 1 tab == 1 file workflow. This will become cumbersome. You may want to look into Vim's buffers. Some links on buffer usage: Using Vim's tabs like buffers, Why do Vim experts prefer buffers over tabs?, and Use buffers effectively. – Peter Rincker Feb 22 '17 at 23:52
  • I appreciate your concern, but that is not how I use vim. I usually have at least 3 different buffers open in a given tab (business logic, automated tests, and a terminal for test output). I add/remove more splits as needed, but if I have to switch focus I want to be able to move to a new workspace and then come back to the old one and have it look exactly how I left it. I find the visual queue of the window layout helps quite a bit with the cognitive load of context switching. – Floegipoky Feb 23 '17 at 18:49
  • 1
    Great use of tabs. As an alternative and if you do no share buffers across tab pages you may want to look into using :set switchbuf=usetab and :sb to switch between buffers. See :h 'swb' and :h :sb. It isn't perfect but may provide some usefulness – Peter Rincker Feb 23 '17 at 18:54

1 Answers1

7

As far as I'm aware, there is no default way to do this. I looked into the ex command tabnext, which accepts a count, but functions exactly the same as gt (that is, it moves to tab page {count}, not {count} pages forward):

:tabn[ext] {count}
{count}<C-PageDown>
{count}gt   Go to tab page {count}.  The first tab page has number one.

However, this isn't very hard to configure! This vimscript mapping does what you're looking for:

nnoremap <leader>gt :<C-u>exec 'normal '.repeat("gt", v:count1)<cr>

This literally just simulates pressing gt over and over as many times as you need. With no count given, it will default to 1.

I picked <leader>gt somewhat arbitrarily. Of course, you can remap this to whatever is easiest or most convenient for you, whether it's a separate binding, or you choose to override the default gt.

DJMcMayhem
  • 17,581
  • 5
  • 53
  • 85