Beginners Guide to Tabs in Vim

Introduction to tabs in Vim

Tabs are a very common feature on many IDEs, however when I have seen people use Vim it seems rare for them to use tabs.

Of course Vim has a great tab feature built in (no need to install any Vim plugin), and once you start getting used to its commands you will find that you quickly get the hang of it.

How to create new tabs/open files in new tabs in Vim

CommandDescription
:tabedit FILENAME

(also just :tabe FILENAME works)

Open a file in a new tab
:tabclose

(also just :tabc)

Close current tab.
:tabonly

(also just :tabo)

Close all OTHER tabs (leave ONLY currently selected tab)
ctrl-w T If current file is part of a split view, then open currently selected split as a new tab

How to switch between tabs/move to a different tab

Moving between tabs is easy!

To move to the next tab: gt

To move to the previous tab: gT

If you wanted to move to a certain tab (based on its position - the one on the far left is #1), you do the following command: #gt - replace # with the number. For example to go to the 3rd tab type 3gt.

How to rearrange tabs in Vim

CommandDescription
tabmove #

(where # is a number)

Move current tab to position #
tabmove Move current tab to the end

.vimrc for better tab experience in Vim

Here are some useful lines to add to your .vimrc. Some of this is based on the excelent amix/vimrc config, I recommend you check it out on Github.

#Better tab experience - from https://webdevetc.com/
map <leader>tn :tabnew<cr>
map <leader>t<leader> :tabnext
map <leader>tm :tabmove
map <leader>tc :tabclose<cr>
map <leader>to :tabonly<cr>

Comments Beginners Guide to Tabs in Vim