Vim keyboard shortcut to move around tabs

24,012

Solution 1

gt is the keyboard shortcut for :tabnext and gT for :tabprevious.

If you prefer the typical Ctrl + Tab, define the following mappings in your ~/.vimrc:

" CTRL-Tab is next tab
noremap <C-Tab> :<C-U>tabnext<CR>
inoremap <C-Tab> <C-\><C-N>:tabnext<CR>
cnoremap <C-Tab> <C-C>:tabnext<CR>
" CTRL-SHIFT-Tab is previous tab
noremap <C-S-Tab> :<C-U>tabprevious<CR>
inoremap <C-S-Tab> <C-\><C-N>:tabprevious<CR>
cnoremap <C-S-Tab> <C-C>:tabprevious<CR>

Solution 2

This is taken from Vim Wikia:

gt            go to next tab
gT            go to previous tab
{i}gt         go to tab in position i

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

Hope it helps.

Solution 3

Maybe

  • Ctrl+PageUp
  • Ctrl+PageDown

? But it doesn't work if you have some gnome-terminal tabs and vim terminal tabs inside. You need

  • Ctrl+Alt+PageUp
  • Ctrl+Alt+PageDown

for vim and

  • Ctrl+PageUp
  • Ctrl+PageDown

for gnome-terminal.

Solution 4

g+t and g+T are Vim's shortcuts to jump to next & previous tabs.

You can use <C-Tab> and <C-S-Tab> to map within Vim but you'll probably need to help your terminal produce correct key codes. Depending on your terminal,

urxvt, add to your .Xresources file:

URxvt*keysym.C-Tab:    \033[27;5;9~
URxvt*keysym.C-S-Tab:  \033[27;6;9~

Alacritty, under key_bindings, add following to your ~/.config/alacritty/alacritty.yml:

- { key: Tab,  mods: Control,        chars: "\x1b[27;5;9~" }
- { key: Tab,  mods: Control|Shift,  chars: "\x1b[27;6;9~" }

Solution 5

This might be a bit extreme for some, but you can do:

nmap <Left> gT
nmap <Right> gt

Turns out you really don't need the arrow keys in normal mode (just use hjkl keys to navigate) and you don't need to change tabs in edit mode. In any case using gt and gT to change tabs is absurd.

Share:
24,012
Melkar Muallem
Author by

Melkar Muallem

Updated on June 07, 2021

Comments

  • Melkar Muallem
    Melkar Muallem almost 3 years

    I used to know this keyboard shortcut which makes you move around Vim tabs in the terminal, similar to Ctrl+tab in a browser.

    I've been looking all over the Internet and I can't find it anymore. Any ideas?

    P.S.: You had to press two letters simultaneously.

  • Melkar Muallem
    Melkar Muallem over 11 years
    alright so i just found it the answer is: tap g+t first g then t
  • Melkar Muallem
    Melkar Muallem over 11 years
    alright so i just found it the answer is: tap g+t first g then t
  • TallChuck
    TallChuck about 7 years
    but then you'd have to move your hand all the way over to the arrow keys... I actually kind of like this idea--don't mind my sarcasm. Alternately, maybe you could map it to gh for left and gl for right
  • n_moen
    n_moen over 2 years
    Thanks for this. I should have done this much, much sooner.
  • Xentatt
    Xentatt about 2 years
    Nice! Loved it.