tags:

views:

236

answers:

2

I was trying to switch from a tab to another tab (which may not be adjacent to the previous tab) in VIM. Is there any shortcut for that, like we have Ctrl-p/Ctrl-n for switching to adjacent tabs?

Also, I was trying to write a key mapping which will give a variable as input to a function and do the operation. For instance, let's say I press Ctrl-5 and a function (written by the user) will be called and given as input 5, and the cursor will go to tab 5 (if there is any 5th tab opened).

Can you please suggest how this can be done?

+4  A: 

use 5gt to switch to tab 5

:tabn[ext] {count}

{count}gt

Go to tab page {count}. The first tab page has number one.

you can also bind it to a key:

:map <C-5> 5gt
:imap <C-5> <C-O>5gt

(Mapping Ctrl-<number> could be different/impossible for some terminals. Consider Alt-<number> then)

Antony Hatchkins
+4  A: 

Tackling only your first question, and quoting from help tabs in vim:

{count}gt       Go to tab page {count}.  The first tab page has number one.
{count}gT       Go {count} tab pages back.  Wraps around from the first one
                to the last one.

ie, typing 3gt goes to the third tab, 3gT goes 3 tabs back from the current tab.

James Polley
not exactly. 3gt moves to the third tab, not 3 tabs forward
Antony Hatchkins
urgh. That's urghy.
James Polley