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 gif 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.
Was this useful? Help us improve!
With your feedback, we can improve VimTricks. Click a link to vote:
This is what my Left and Right arrows keys are mapped to. I also set 'hidden', so :N and :n without the :w:
" Edit the previous/next file.
nnoremap <silent> <Left> :previous<CR>
nnoremap <silent> <Right> :next<CR>