Learn Vim at your own pace with my self-study Core Vim Course.

Learn more

Learn Vim at your own pace with my self-study Core Vim Course.

Populating the arglist

#42

Run time:

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.

Shownotes

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:

  1. one or more filepaths (separated by whitespace)
  2. a wildcard
  3. a backtick expression
  4. 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.

Further reading

Comments

Level-up your Vim

Training

Boost your productivity with a Vim training class. Join a public class, or book a private session for your team.

Drew hosted a private Vim session for the shopify team that was one of the best workshops I have ever attended.

John Duff, Director of Engineering at Shopify

Publications

Make yourself a faster and more efficient developer with the help of these publications, including Practical Vim (Pragmatic Bookshelf 2012), which has over 50 five-star reviews on Amazon.

After reading it, I've switched to vim as my default editor on a daily basis with no regrets. ★★★★★

Javier Collado

Learn to use Vim efficiently in your Ruby projects

In association with thoughtbot, one of the most well respected Rails consultancies in the world, I've produced a series of screencasts on how to make navigating your Ruby projects with Vim ultra-efficient. Along the way, you’ll also learn how to make Ruby blocks a first-class text object in Vim. This lets you edit Ruby code at a higher level of abstraction. Available to buy from thoughtbot..