Working with tabs


Run time:

This episode covers the essential commands for working with Vim’s tab pages: opening and closing, switching, and moving them.


Opening & closing tabs

The following commands are useful for opening and closing tabs.

command action
:tabe[dit] filename Open filename in a new tab
ctrl-W T Move current split window into its own tab
:q Close window, closing tab if it contains a single window
:tabc[lose] Close the current tab page and all its windows
:tabo[nly] Close all tabs apart from the current one

Switching tabs

When you have multiple tabs open, you can switch between them using the mouse, or the following commands:

command action
gt Move to next tab
gT Move to previous tab
#gt Move to tab number #

I’m accustomed to the tab switching shortcuts of Firefox, so to port these into my Vim environment, I include the following in my .vimrc:

" For mac users (using the 'apple' key)
map <D-S-]> gt
map <D-S-[> gT
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-0> :tablast<CR>

" for linux and windows users (using the control key)
map <C-S-]> gt
map <C-S-[> gT
map <C-1> 1gt
map <C-2> 2gt
map <C-3> 3gt
map <C-4> 4gt
map <C-5> 5gt
map <C-6> 6gt
map <C-7> 7gt
map <C-8> 8gt
map <C-9> 9gt
map <C-0> :tablast<CR>

Rearranging tabs

In MacVim, you can rearrange tabs by dragging and dropping them with the mouse. The following commands can be used in Terminal Vim:

command action
:tabmove Move current tab to the end
:tabmove 0 Move current tab to the beginning
:tabmove 1 Move current tab to become the 2nd tab

Level-up your Vim


Boost your productivity with a Vim training class. Join a public class, or book a private session for your team.

Drew hosted a private Vim session for the shopify team that was one of the best workshops I have ever attended.

John Duff, Director of Engineering at Shopify


Make yourself a faster and more efficient developer with the help of these publications, including Practical Vim (Pragmatic Bookshelf 2012), which has over 50 five-star reviews on Amazon.

After reading it, I've switched to vim as my default editor on a daily basis with no regrets. ★★★★★

Javier Collado

Learn to use Vim efficiently in your Ruby projects

In association with thoughtbot, one of the most well respected Rails consultancies in the world, I've produced a series of screencasts on how to make navigating your Ruby projects with Vim ultra-efficient. Along the way, you’ll also learn how to make Ruby blocks a first-class text object in Vim. This lets you edit Ruby code at a higher level of abstraction. Available to buy from thoughtbot..