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

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

CommandDescription
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 https://webdevetc.com/
  2.  
  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>

Subscribe to my spam free newsletter for other Laravel updates like this

I never spam, and only email when I have a good in-depth post published on my site (mostly about Laravel). You can also follow me on social media to get updates.

webdevetc profile pic
webdevetc

I'm a late 20's web developer, specialising in Laravel, but work with other PHP frameworks and associated technologies (such as JS). I mostly write about PHP here. Contact me here. Need to hire or work with a contract PHP software developer in London, UK (or freelance)? Contact me and check my availability.

Leave a Comment