Reputation: 433
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.
Upvotes: 42
Views: 38003
Reputation: 1817
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"
Upvotes: 9
Reputation: 14548
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.
Upvotes: 0
Reputation: 111
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
Upvotes: 8
Reputation: 65
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 + ← / ↑ / → / ↓
Upvotes: 0
Reputation: 18147
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
Upvotes: 0
Reputation: 520
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.
Upvotes: 39
Reputation: 43
: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>
Upvotes: 0
Reputation: 1208
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.
Upvotes: 5
Reputation: 9813
Maybe
? But it doesn't work if you have some gnome-terminal tabs and vim terminal tabs inside. You need
for vim and
for gnome-terminal.
Upvotes: 14
Reputation: 172570
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>
Upvotes: 51