Populating the arglist
The arglist wouldn’t be much use if we had to quit and relaunch Vim every time we wanted to change its contents. In this episode, we’ll learn how to set the contents of the arglist using the :args command, which can receive filepaths, globs, or even backtick expressions.
I’m running a Core Vim masterclass online, on Monday, June 3rd. Tickets cost £95, but you can get the earlybird discount price of £80 if you buy yours before May 24th. Come and see how Vim can blow your mind, or your money back.
When run with no arguments, the :args command reveals the contents of the arglist. But when a valid {arglist} is passed to the :args command it sets the contents of the arglist:
| Ex command | effect |
|---|---|
:args |
show the contents of the arglist |
:args {arglist} |
set the contents of the arglist |
The {arglist} could be:
- one or more filepaths (separated by whitespace)
- a wildcard
- a backtick expression
- a combination of the above
As a general rule: anything that you can provide as an argument to the Vim executable at the commandline can also be supplied as an argument to the :args command.
Backtick expression are particularly powerful. In the video, I use the simple example of running :args `cat .toc` to use the contents of a plaintext file to populate the arglist, but we could put anything inside that backtick expression. So long as the subshell returns a list of filepaths, then Vim will consider it as valid input. For example, you could use the output of find or grep, or even a shell script of your own.