Vim Tips Wiki
Tip 1295 Printable Monobook Previous Next

created 2006 · complexity basic · author tjs · version 6.0

Add these to your vimrc to make Vim behave like every other app that uses tabs. If you're not on a Mac, switch the D to another character, D maps the command key.

"tab mappings
map <D-1> 1gt
map <D-2> 2gt
map <D-3> 3gt
map <D-4> 4gt
map <D-5> 5gt
map <D-6> 6gt
map <D-7> 7gt
map <D-8> 8gt
map <D-9> 9gt
map <D-t> :tabnew<CR>
map <D-w> :tabclose<CR>

So commandkey+1-9 switches tabs, commandkey+t opens a new tab, commandkey+w closes the current tab etc.


That is a good tip for Mac users however I think these commands should be placed in gvimrc as tabs in terminal Vim don't exist.

they do

vimrc is read by gvim if there is no gvimrc btw.

You can use tabs in terminal version of Vim on Mac, but cmd+T is wired to show the font window for Terminal, and cmd+1 is Terminal window 1 etc.

I have

nmap <D-[> gT
nmap <D-]> gt

to map cmd+[ and ] to prev/next tabs.

gvim doesn't seem to know the difference between [ and { with cmd, so couldn't get cmd+shift+[ like safari

This gives standard windows tab-swapping ala Firefox:

map <C-Tab> :tabn <CR>
map <C-S-Tab> :tabp <CR>

This works for me for binding command-left and command-right to tab-prev and tab-next on mac os x:

map <C-D-\> :tabp<CR>
map <C-D-]> :tabn<CR>

Instead of simply opening a new tab, I find it more useful to use tabfind to search for and open anything in my path.

nmap <D-t> <Esc>:tabfind **/
nmap <D-t> <Esc>:tabnew<CR>

For me the following worked (where <M-1> didn't):

map <Esc>1 1gt
map <Esc>2 2gt