How do I step through the files in my argument list one at a time?
Answer
:next
Explanation
When Vim is opened with multiple files (e.g., vim *.py) or after populating the argument list with :args, those files form an argument list. Instead of switching between them with buffer commands, you can step through them sequentially using :next and :prev (also spelled :previous). This makes reading or editing a batch of files feel like flipping through pages.
How it works
:nextmoves to the next file in the argument list and loads it into the current window:prevor:previousmoves back to the previous file:firstjumps directly to the first file in the list:lastjumps to the final file:argsshows the full list with the current file highlighted in brackets- Each command will warn you if the current buffer has unsaved changes; add
!to force::next!
Example
" Open all Python files in the directory
vim *.py
" See what's loaded
:args
" Output: [main.py] utils.py tests.py
:next " → utils.py
:next " → tests.py
:prev " ← utils.py
:first " ← main.py
Tips
- Populate the argument list from inside Vim:
:args **/*.py(requirespath+=**) - Use
:argdo {cmd}to run a command on every file at once instead of stepping through manually :wnextcombines:writeand:nextto save the current file and advance in one step