Wednesday, May 4, 2011

Custom replacements in VI

Thanks to Steve for this pearl of VI wisdom.
For search and replace operation in VI, parenthesis remembers the item. This can be used for custom replacements later. Try the command below on a file with this data:

29 5 2010
30 6 2011

:1,$s/[0-9]* \([0-9]*\) \([0-9]*\)/\2 \1/
VI can remember 9 such fields.

No comments:

Post a Comment