Wednesday, May 25, 2011

.vimrc: switching tabs in MacVim

I'm not yet all-command-line all-the-time. (ACLATT?) Sometimes I use, say, browsers. So I've been liking MacVim.

I also like how alt-tab (or command-tab) switches between windows, while control-tab switches between tabs in my browser window. When I found out that MacVim windows can have multiple tabs too, I wanted control-tab to work there too. Hence, the newest (MacVim-specific) addition to my .vimrc:

" In MacVim, you can have multiple tabs open. This mapping makes
" ctrl-tab switch between them, like browser tabs.
" I don't think it matters whether I use noremap or map, unless
" :tabnext gets bound to something else, which would be weird.
noremap <c-tab> :tabnext<cr>


  1. This is absolutely awesome -- now I can use years worth of finger muscle-memory from switching browser tabs in Vim. Thanks Dan. :)

  2. Thanks a lot! This is what I am looking for!

  3. Sorry for the noise, here is the complete (and "entitied") code, which should be put in .gvimrc and also checks for MacVim:

    if has("gui_macvim")
    " In MacVim, you can have multiple tabs open. This mapping makes Ctrl-Tab
    " switch between them, like browser tabs. Ctrl-Shift-Tab goes the other way.
    noremap <C-Tab> :tabnext<CR>
    noremap <C-S-Tab> :tabprev<CR>

    " Switch to specific tab numbers with Command-number
    noremap <D-1> :tabn 1<CR>
    noremap <D-2> :tabn 2<CR>
    noremap <D-3> :tabn 3<CR>
    noremap <D-4> :tabn 4<CR>
    noremap <D-5> :tabn 5<CR>
    noremap <D-6> :tabn 6<CR>
    noremap <D-7> :tabn 7<CR>
    noremap <D-8> :tabn 8<CR>
    noremap <D-9> :tabn 9<CR>
    " Command-0 goes to the last tab
    noremap <D-0> :tablast<CR>

    1. Hey Ryan- thanks for cleaning this up; I've deleted your earlier comments as this one seems to have it all. And thanks for the tip!

  4. Thank you. This had been a thorn in my side for awhile.