I
use !$ (Section 30.3) a lot, but my favorite history substitution is
!
:n
*
, where n
is a
number from 0 to 9. It means "take arguments n
through the last argument on the previous command line." Since I tend to use
more than one argument with Unix commands, this lets me type the arguments
(usually filenames) only once. For example, to use RCS (Section 39.5) and
make an edit to article files named Section
35.5 and Section 29.2 for
this book, I did:
%co -l 1171.sgm 6830.sgm 2340.sgm
RCS/1171.sgm,v -> 1171.sgm ... RCS/2340.sgm,v -> 2340.sgm revision 1.8 (locked) done %vi !:2*
vi 1171.sgm 6830.sgm 2340.sgm 3 files to edit ... %ci -m"Changed TERM xref." !*
ci -m"Changed TERM xref." 1171.sgm 6830.sgm 2340.sgm ...
In the first command line (co), I typed the
filenames as arguments 2, 3, and 4. In the second command line (vi), I used !:2*
; which grabbed arguments 2 through the last (in this case,
argument 4) from the first command line. The result was a second command line
that had those three filenames as its arguments 1, 2, and 3. So, in the third
command line (ci), I used !*
to pick arguments 1 through the last from the
previous (second) command line. (!*
is
shorthand for !:1*
.)
You can also grab arguments from previous command lines. For example, !em:2*
grabs the second through last arguments on
the previous emacs command line (command line
starting with "em"). There are lots more of these in Section 30.8.
If these examples look complicated, they won't be for long. Just learn to count to the first argument you want to grab. It took me years to start using these substitutions — but they've saved me so much typing that I'm sorry I didn't get started earlier!
— JP