vimtricks.wiki Concise Vim tricks, one at a time.

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

  • :next moves to the next file in the argument list and loads it into the current window
  • :prev or :previous moves back to the previous file
  • :first jumps directly to the first file in the list
  • :last jumps to the final file
  • :args shows 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 (requires path+=**)
  • Use :argdo {cmd} to run a command on every file at once instead of stepping through manually
  • :wnext combines :write and :next to save the current file and advance in one step

Next

How do I make Neovim restore the scroll position when navigating back through the jump list?