Edit files sequentially

3.7
(152)

We’ve published a few tips about the args list, a way to load a list of files into Vim to operate off of as a set. One tip I use often myself is Open all files in a directory, which splits all the files in a directory on my screen at once using the args list. The ability to see a set of files simultaneously on my screen and compare and edit them all at once is extremely useful in my everyday software engineer life.

But I recently discovered another neat trick that will also earn a spot in my regular rotation: write and next:

  • :wn – Write the file and move to the next file in the args list

To use this, simply first load a list of files into the args list. One way to do that is with a file glob:

:args path/to/file/*.ext

The first file in the list will automatically open. Perform your edits and then invoke :wn. Upon writing, Vim will open the next file from the args list. In this way, you can work through the entire list very quickly.

Here’s a short video where I demonstrate this in action. First I load the args list with all the files in the _posts directory using :args _/posts/*. Next, I edit the first file and use :wn. The file is saved and I’m taken to the next file in the directory automatically. I can repeat until the end of the list.

How useful was this tip?

Average rating 3.7 / 5. Vote count: 152

No votes so far! Be the first to rate this tip.

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?

Written by

Colin Bartlett

105 Posts

Vim enthusiast and software developer for more than 20 years.
View all posts