-
Enter the command(s) you want to execute onto one or more lines of
the file you're editing.
-
Yank or delete the line(s) into a named buffer with a command like
"ay$ or "bD.
-
To use the function, type a command like @a or
@b. You can repeat the function by typing
@@ or a dot (.). Use u or
U to undo the effects of the
@-function.
Here's an example. You're editing a
long HTML file with lines like these:
<STRONG>Some heading here</STRONG>
<STRONG>Another heading here</STRONG>
When you see one of those lines, you need to change the
STRONG s to either H3 or
H4. A global substitution with
:%s won't do the job because some
lines need H3 and others need
H4; you have to decide line-by-line as you work
through the file. So you define the function @a to
change a line to H3, and @b to
change to H4.
To design an @-function, start by thinking how
you'd make the changes by hand.
You'd probably move to the start of the line with
0, move to the right one character with
l, type cw to change the word
STRONG, and type in H3 (or
H4). Then you'd press ESC to
return to command mode. After going to the end of the line with
$, you'd move to the character
after the slash with T/, then change the second
STRONG the way you fixed the first one.