History
Article Edit this page Discussion

Alternative tab navigation

From Vim Tips Wiki

Jump to: navigation, search

Tip 1221 Previous Next Created: May 8, 2006 Complexity: basic Author: Kim Schulz aka KimuSan Version: n/a


Here is an alternative way to open and navigate tabs in Vim 7. Add the following to your vimrc:

" tab navigation like firefox
:nmap <C-S-tab> :tabprevious<CR>
:nmap <C-tab> :tabnext<CR>
:map <C-S-tab> :tabprevious<CR>
:map <C-tab> :tabnext<CR>
:imap <C-S-tab> <Esc>:tabprevious<CR>i
:imap <C-tab> <Esc>:tabnext<CR>i
:nmap <C-t> :tabnew<CR>
:imap <C-t> <Esc>:tabnew<CR>

You can open a new tab with ctrl-t, go forward through the tabs with ctrl-tab and backwards with ctrl-shift-tab.

This way of navigating resembles the way it is done in Firefox.

[edit] Comments

I ended up with:

map th :tabnext<CR>
map tl :tabprev<CR>
map tn :tabnew<CR>
map td :tabclose<CR>

For something like gnome-terminal tab-related key shortcuts:

:nmap <C-S-t> :tabnew<CR>
:imap <C-S-t> <Esc>:tabnew<CR>
:imap <C-S-w> <Esc>:tabclose<CR>

Didn't exactly work in Windows' gvim. Had to put it into _gvimrc, like this:

:map <C-S-tab> :tabprevious<CR>
:map <C-tab> :tabnext<CR>
:map <C-t> :tabnew<CR>

Why not add Ctrl-w to close tabs?

:map <C-w> :tabclose<CR>

I just use the way that Vim provides and it work well:

  • gt for tabnext
  • gT for tabprevious

Try

:map <S-h> gT
:map <S-l> gt

That way you can hold down the shift key while you scroll left and right through the tabs with 'h' and 'l'.


<C-tab> , <C-S-tab> don't work on Eterm, aterm, xterm

We can use <C-PageDown> and <C-PageUp> instead of <C-tab> and <C-S-tab> This's the default way in Vim 7. By the way, this also work on Firefox.


This tip is really good. But the key sequences used for switching/creating the tabs is clashing with other features of Vim. For example:

  • CTRL+T is used for jumping to previous tags [exuberant ctags].
  • CTRL+W is used for jumping to next split window in multiple windows
  • CTRL+TAB is captured by KDE itself to switch workspaces.

Can you give a nice key combinations which will work with all these features ?. I know tabs is a new feature of vim7. But this script can become awesome if worked properly on.


Vim 7 already has <C-PageUp> and <C-PageDown> to cycle through tabs. To open and close them I added

nmap <C-Insert> :tabnew<CR>
nmap <C-Delete> :tabclose<CR>

(not for insert or visual mode because they do something else then).


I know that Z and X both perform functions in normal mode, but I never use them, so I just mapped:

:nmap Z :tabprev<CR>
:nmap X :tabnext<CR>

That way shift-z and shift-x takes me forward and backward. It's a lazy, ergonimic one hand solution.


I found this tip

autocmd VimEnter * tab all
autocmd BufAdd * exe 'tablast | tabe "' . expand( "<afile") .'"'

I neglected to RTFM. The key combination is <tab number>gt. Here's a handy alternative to switch to tab-N by pressing Alt-FN

map <A-F1> 1gt
map <A-F2> 2gt
map <A-F3> 3gt
map <A-F4> 4gt
map <A-F5> 5gt
map <A-F6> 6gt
map <A-F7> 7gt
map <A-F8> 8gt
map <A-F9> 9gt
map <A-F0> 10g

Rate this article:

Share this article:

Hubs Highlights International Sites Wikia messages
Entertainment
Gaming
Cartoons & Comics
Science Fiction
Hobbies
Sports
See all...
Grand Theft Auto Wiki
Doctor Who
Legend of Zelda Wiki
Terminator Wiki
Everquest II Wiki
Mystery Science Theater 3000
German
Spanish
Chinese
Japanese
More...
Wikia is hiring for several open positions
Send this article to a friend
"Alternative tab navigation"
 
 
Hi!

I thought you'd like this page from Wikia!

http://vim.wikia.com

Come check it out!
Send confirmation