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 |