Beginners Guide to Tabs in Vim

Beginners Guide to Tabs in Vim Thumbnail image

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

: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 TIf 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

tabmove # (where # is a number)Move current tab to position #
tabmoveMove 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.

  1. #Better tab experience - from
  3. map <leader>tn :tabnew<cr>
  4. map <leader>t<leader> :tabnext
  5. map <leader>tm :tabmove
  6. map <leader>tc :tabclose<cr>
  7. map <leader>to :tabonly<cr>
webdevetc profile pic

I am a 29 year old freelance backend web developer from London, mostly focusing on PHP and Laravel lately. This is my site - I mostly write about PHP here. Contact me here (especially for any contracting jobs early 2019 in London ;) ).

Leave a Comment