39

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.

Matthias Braun
  • 32,039
  • 22
  • 142
  • 171
Melkar Muallem
  • 403
  • 1
  • 4
  • 6

9 Answers9

46

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>
Ingo Karkat
  • 167,457
  • 16
  • 250
  • 324
37

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.

Mickey
  • 501
  • 4
  • 8
12

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.

xav
  • 5,452
  • 7
  • 48
  • 57
Anton Bessonov
  • 9,208
  • 3
  • 35
  • 38
9

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~" }
rafi
  • 1,648
  • 2
  • 18
  • 23
  • Is it possible for you to explain/link a source explaining the key codes stuff? Like, how do you find which key code to use for which keys? – StaticESC Jun 06 '23 at 04:54
8

The best is to map your “L” and “H” keys since these are the keys for cursor movement (Right and Left Respectively) also and we don't have to remember anything.

map <C-L> gt
map <C-H> gT

This is probably the most natural way of navigating tabs where there is no need to practice or remember anything. Just press: Ctrl+L (or long-press L to navigate further). Similarly, if you want to navigate towards the left press Ctrl+H.

Try it out and only then you can understand the benefit since the keys mapped are the same as used for your cursor

Nathan Dai
  • 392
  • 2
  • 11
pgoyal
  • 91
  • 1
  • 3
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.

nicodjimenez
  • 1,180
  • 17
  • 15
  • 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 – TallChuck Jan 27 '17 at 20:51
0
:nmap <C-S-tab> :tabprevious<cr>
:nmap <C-tab> :tabnext<cr>
:nmap <C-t> :tabnew<cr>
:map <C-t> :tabnew<cr>
:map <C-S-tab> :tabprevious<cr>
:map <C-tab> :tabnext<cr>
:map <C-w> :tabclose<cr>
:imap <C-S-tab> <ESC>:tabprevious<cr>i
:imap <C-tab> <ESC>:tabnext<cr>i
:imap <C-t> <ESC>:tabnew<cr>
Héctor
  • 43
  • 9
0

Adding few more shortcut with @Mickey answer

gt    -   go to next tab
gT    -   go to previous tab
{i}gt -   go to tab in position i
1gt   -   go to first tab
1gT   -   go to last tab
Samselvaprabu
  • 16,830
  • 32
  • 144
  • 230
0

Just try this:

way1:

if you want to switch between few tabs quickly in a virtical or horizonal way.

Ctrl + w w

way2:

also , if you want to switch by arrow key flexibly.

Ctrl + w + raise your hand from keyboard, and then + / / /