Vim keyboard shortcut to move around tabs
Asked Answered
O

10

41

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.

Oxyacetylene answered 22/9, 2012 at 18:52 Comment(3)
:tabn, :tabp Map them as map <C-PageUp> :tabnextNonpayment
May not work for some terminals -see #2978951Assignee
Could you please tick this question as answered by marking the appropriate answer?Ferriferous
T
49

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>
Tamarisk answered 22/9, 2012 at 19:21 Comment(1)
alright so i just found it the answer is: tap g+t first g then tOxyacetylene
L
38

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.

Lombroso answered 21/8, 2015 at 1:27 Comment(0)
C
14

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.

Currie answered 22/9, 2012 at 18:58 Comment(2)
alright so i just found it the answer is: tap g+t first g then tOxyacetylene
CTRL + SHIFT + PAGEUP and CTRL + SHIFT + PAGEDOWN work by default on GVIM for Windows.Anciently
K
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~

kitty, add to your ~/.config/kitty/kitty.conf:

map ctrl+i send_text all \x1b[27;5;105~
map ctrl+tab send_text all \x1b[27;5;9~
map ctrl+shift+tab send_text all \x1b[27;6;9~

Alacritty, add following to your ~/.config/alacritty/alacritty.toml:

[[keyboard.bindings]]
chars = "\u001B[27;5;105~"
key = "I"
mods = "Control"

[[keyboard.bindings]]
chars = "\u001B[27;5;9~"
key = "Tab"
mods = "Control"

[[keyboard.bindings]]
chars = "\u001B[27;6;9~"
key = "Tab"
mods = "Control|Shift"
Kierstenkieselguhr answered 29/4, 2017 at 6:28 Comment(2)
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?Mesne
@Mesne see this comment: https://mcmap.net/q/321793/-how-to-map-shift-enter/…Kierstenkieselguhr
D
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

Derosier answered 6/6, 2021 at 16:33 Comment(0)
J
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.

Jasisa answered 13/8, 2015 at 16:54 Comment(1)
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 rightTenner
H
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>
Hummocky answered 12/4, 2020 at 5:19 Comment(0)
N
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
Nombles answered 7/11, 2020 at 15:18 Comment(0)
C
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 + / / /

Carious answered 18/3, 2021 at 10:43 Comment(0)
R
0

As other answers have mentioned, gt (g for the "go to" command, and t for tab).

Which can be prefixed by the tab number, as in 1gt to go to tab one. (which IMHO is weird, as that syntax should mean "move N tabs from the current one", as happens with all other movement prefixes, e.g. 2w)

join that knowledge with the fact that most terminals give you either <D-n> or some weird symbol when you press Alt+1 and you can use:

(NOTE! you must check what you get by actually typing ALT+1 on your terminal)

"tabs like firefox
"must use the especial chars (created in ABNT2 keyboard, tested on US keyboard. Under both X and wayland)
"when you press alt-1...0
noremap ± 1gt
noremap ² 2gt
noremap ³ 3gt
noremap ´ 4gt
noremap µ 5gt
noremap ¶ 6gt
noremap · 7gt
noremap ¸ 8gt
noremap ¹ 9gt
noremap ° 10gt
"and now the same for right_alt-1..0
noremap ¹ 1gt
noremap ² 2gt
noremap ³ 3gt
noremap £ 4gt
noremap ¢ 5gt
noremap ¬ 6gt
noremap { 7gt
noremap [ 8gt
noremap ] 9gt
noremap } 10gt
"and for mac command+1,2,3... support:
noremap <D-1> 1gt
noremap <D-2> 2gt
noremap <D-3> 3gt
noremap <D-4> 4gt
noremap <D-5> 5gt
noremap <D-6> 6gt
noremap <D-7> 7gt
noremap <D-8> 8gt
noremap <D-9> 9gt
noremap <D-0> 10gt

Now, "typing" those symbols in command mode will move you to tabs. The result is that you can move tabs like any other GUI application! ALT+1 move to tab one, ALT+2 for tab two, etc.

And you can still type those chars if you need to because we are only remapping in command mode.

Rhapsodize answered 8/2 at 10:50 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.