When we open vim with multiple files they will be in their own buffers. If we open a new file with :e for example, it will be in a new buffer and that’s good, but there is one extra with vim arguments. We have a list as arguments and we can do operations on them. Does not matter how many files we have open, the args list will not change if we don’t explicitly tell vim to do that.

For now, we learn how to navigate between them. With :args we can list our args list and the active element will be marked with [], for example here we have 3 files in the args list and Dockerfile is the active entry. It does not mean Dockerfile is the active buffer, it means a pointer tells us we are on that position in the args list.

:args
config.yaml  [Dockerfile] Makefile

With :n[ext]), we can jump to the next file. It will load the buffer into the active window. With the same logic we have :prev[ious], which obviously goes backwards in the args list. Important to note, it does not fold back to itself, it’s not a ring, it’s a simple list. If we are on the last entry of the args list and we try to use :n[ext], vim will tell you “Cannot go beyond last file”.

There is one extra command that can be useful and that’s the :wn[ext] command. It saves the current file and jumps to the next, same works with :wp[revious]. It can be very useful if we want to do some operations on more than one files, but it can’t be solved with other external tools like sed. We can issue our commands, then we can end with :wn and we can work on the next file, repeat until we reach the end of the args list.

It’s important to understand how it works, because tomorrow we will use the args list to do some fancy magic.