How to open multiple files using single Vim editor command in Linux

Vim is no doubt a very powerful command line text editor, but it's not easy to master. The tool offers a sea of features, which is why remembering each and every functionality isn't an easy task.

However, it's always good to know the features that are helpful in your day-to-day task. One such feature - that I am sure most of you'd find beneficial - is the ability to open multiple files in one go, and to be able to switch between those files seamlessly.

In this tutorial, we will discuss how you can do this. Please be aware that all examples/instructions mentioned in this article/tutorial have been tested on Ubuntu 22.04.

Open multiple files and easily switch between them

This is very easy - all you have to do is to use the -p command line option. For example:

vim -p file1 file2

The following screenshot shows how the two files opened in a single Vim window:


As you can see, the files opened in different tabs. To switch from one tab to another, you can use the :bn and :bp commands while the editor is in command mode.

That's it. In case you want to learn more about Vim (including advanced stuff), you can head here. There is also a guide for opening files on Windows.

Leave a Comment