How to Edit Multiple files and Switch between those in VIM using Buffers

Updated on September 3, 2017

I have been using VIM editor for quite a long time, but until today I didn’t know how to open and edit multiple files at once and switch between those quickly. I’m writing this tutorial for people like me who didn’t know about Buffers in VIM editor. To edit multiple files using vim, you can simply pass all files as arguments to the ‘vim‘ command. For e.g., vim text1 text2 text3. The vim will open all files and let you switch between those using ‘buffers‘ command.

How to Edit multiple files at once

Type the below command to open or edit multiple files at once,

$ vim text1 text2 text3

The ‘vim‘ will open all the files (e.g., text1, text2 & text3) and lets you switch to one file at a time. To switch to next opened file, you just need to type ‘:n

:n

Once you are in the second file (text2), type ‘:n‘ to switch to third file (text3) and switch back to previous file (text2), type”:N” and then again ‘:N‘ to go to first file (text1). Checkout the GIF file below to see how you can use ‘:n‘ and ‘:N‘ to switch between files.

open multiple files in vim

Using Buffers in VIM – Switch from File 1 to File 3

You can use ‘buffers‘ command to find the list of opened files as below:

:buffers
 1 %a "text1" line 2
 2 "text2" line 0
 3 "text3" line 0
Press ENTER or type command to continue

To switch to the desired file (assume, third file), type as below:

:buffer 3

using buffers vim

Was this article helpful?

Related Articles

Leave a Comment