Quote:
I believe there is even a way to write all of these vi commands in a file and execute them while you are vi'ing the file.
I know this is straying from the original topic a little, but I wanted to say that the functionality mentioned by Kelam_Magnus is really cool
and powerful. The command is ! and like many vi commands, is followed by a movement to indicate how much text to operate on. In this case, the defined amount of text is passed to the OS for processing, and all the passed text is replaced by the output of the processing.
Say you have a paragraph of plain text comments, and some lines are too long, some too short. Put your cursor at start of paragraph and type !} which says process all text thru EOP, and when prompted at the colon prompt, type
adjust or
adjust -m66, and the text will be replaced by the output of /bin/adjust.
Or create a script called addhori.sh:
awk '{printf "%9d%9d%9d%9d\n",$1,$2,$3,$1+$2+$3}'
In vi, place your cursor on the first of the four lines:
5 5 5
3 4 5
22 22 22
9 9 9
and this time let's process the current line plus next 3 lines: !3j
and at the colon prompt, type: addhori.sh
The four lines will be replaced with the awk output, in this case it will be the same 4 lines but formatted and with a total column added. It does not have to be line-per-line replacement. All lines could be replaced with a single line, or the 4 lines above could become the same 4 lines plus a total line below them (addvert.sh), each line could become two lines, whatever.
And of course, just type "u" to undo.
And for added functionality, some of the scripts I write for vi external processing utilize passed parameters.