Tuesday, February 2, 2010

vi multiple lines ; repeat last commands

To join multiple lines in vi, use 5,9j! in cmd mode.
We know that J (note uppercase) on a line joins it with the next line. "!" preserves whitespace between the lines but it didn't in ksh shell.

To apply last used substitute command through out the file:
e.g. %s/this/that/g

& to repeat the last used substitution for the first occurrence on the current line
&g to change all on the current line
%&g for entire file

Use . to repeat the last insert command. It inserts the last few inserted words/lines after the cursor.


No comments:

Post a Comment