tags:

views:

331

answers:

2

Hi,

How do I make Vim switch to a certain tab when I hit Alt+# ? For example, to get to the third tab, I'd hit Alt+3 (like the behavior in Firefox).

Edit: also, how can I make Control + tab == gt, Control + shift + tab == gT

+3  A: 
:nmap <M-1> :tabnext 1<CR>
:nmap <M-2> :tabnext 2<CR>
etc.

See :h :tabnext. Note that by default you can also do Ngt in normal mode where N is the number of the tab you want (starting with 1).

Brian Carper
Hm, this doesn't actually work for me...I'm not sure why. The Ngt tip is nice though.
victor
<M-1>, <M-2> etc. conflict with window manager key bindings on my system, but it seemed to work OK otherwise. <M-9> was unmapped and I tried that and it worked. What kind of problem are you having?
Brian Carper
I'm not sure...it just doesn't end up doing anything. I also don't think I have anything bound to those keys otherwise wouldn't the Firefox shortcuts not work either? I'm on Ubuntu.
victor
Not sure either... worked OK in KDE, and I just tried it in Windows, copy/pasted from my post and it worked OK too. I'm doing this in gvim; if you're doing it in console vim, your terminal may not be allowing Vim to see Alt+N keypresses.
Brian Carper
Hm, Alt+# works in irssi...I'll keep on digging.
victor
Depending on how your system is setup, it's possible that <M-1> only works for the left ALT. Did you try with both ALTs?
Conspicuous Compiler
+1  A: 

This works for me (copied and pasted from my rc):

" Tab Control (others)
 map <A-1> 1gt
 map <A-2> 2gt
 map <A-3> 3gt
 map <A-4> 4gt
 map <A-5> 5gt
 map <A-6> 6gt
 map <A-7> 7gt
 map <A-8> 8gt
 map <A-9> 9gt

Also further goodness:

map <C-Right> <ESC>:tabnext<CR>
map <C-Left> <ESC>:tabprev<CR>
map <C-t> <ESC>:tabnew<CR>

You may want to change it to nmap like the example above to restrict the usage a little better I've been a bit lazy in that respect.

Missed your edit next tab with Ctl-t would be:

map <C-t> :tabnext<CR>

I don't think the tabprevious mapping is possible in vim due to the way it handles uppercase characters see:

http://www.nabble.com/Maping-Ctrl-Shift-s-problems-td22918941.html

To save some time I spent hunting around when I wanted this

Ben