Tabs in Vim

Page Trail: [[ Tabs in Vim ]]
2009-05-28 23:51
Vim logo

Version 7 of Vim introduced tabs to the editor, and these are a few of my tab-related tips. If you aren't familiar with tabs in Vim, start with the basics on The Golden Ratio or Linux.com.

Open Files in Tabs

If you want to open multiple files in their own tabs in a new Vim session, use the -p flag on the command line for vim or gvim. For example, to open all files in the current directory, use the following:

vim -p *

When you give Vim multiple files to edit, its default behavior is to use several buffers. If you want to use tabs as the default behavior instead (that is, without typing the -p flag every time), set up a couple shell aliases. For bash, place these in your ~/.bashrc:

alias vim='vim -p'
alias gvim='gvim -p'

Also, Vim will open a maximum of 10 tabs like this by default. To increase that limit to, for example, 50, add the following to your ~/.vimrc:

set tabpagemax=50

Easier Tab Navigation

When you have more than a few tabs open, it can become difficult to navigate them with only the keyboard. You can use {count}gt to go to the count-th tab (starting with 1), but counting them yourself is a waste of time. Placing the tab number on its label solves this problem.

Vim tab labels

You can see how I set a custom tab label in this commit to my Vim configuration repository. The blog post on The Golden Ratio has another custom tab label you could check out.