How to Open Multiple Files in Vim Splits and Tabs

Updated on

You can open multiple files in vim in splits and tabs right from the terminal.

In the examples below, I have three files in the current directory like this:

.
├── file1
├── file2
└── file3

Open Multiple Files in Horizontal Splits

To open multiple files in horizontal splits in Vim, use the -o flag like this:

vim -o file1 file2

Here’s a screenshot:

Vim horizontal split

Open Multiple Files in Vertical Splits

To open multiple files with vertical splits in Vim, use the -O flag:

vim -O file1 file2

In this screenshot I’ve opened three files in vertical splits:

Vim vertical splits

Open Multiple Files in Vim Tabs

To open multiple files in Vim tabs, use the -p flag:

vim -p file1 file2

Here’s a screenshot:

Vim tabs

One of the great features of Vim is that a tab is an arrangement of panes, not a single file. Each tab can contain a different layout of files, allowing you to move through different layouts of files.

Use gt and gT to rotate through tabs. (Tip: you can move by more than one tab at a time by typing things like 2gt and 3gT.) To move tabs use :tabm (see :h tabm for documentation).

Bash/Zsh Aliases

If you use fzf, these aliases are useful shortcuts:

alias v='vim `fzf`'
alias vof='vim -o `fzf`'
alias vOf='vim -O `fzf`'
alias vpf='vim -p `fzf`'

Video Example

Here’s a short clip that demonstrates all the techniques above:

asciicast

Tagged with: Programming Vim

Feedback and Comments

What did you think about this page? Do you have any questions, or is there anything that could be improved? You can leave a comment after clicking on an icon below.