Tuesday, September 25, 2007

Tip for the day: APPENDING TEXT AT BOTH ENDS

If you need to append some text to both the ends of a string in vi, use the following command in vi:

:/^\(.*\)/s//starttextcomeshere \1 endtextcomeshere/

If "iamworthless" is the text at the position of the cursor in the vi editor, the output of the command:

:/^\(.*\)/s//DONTFEEL \1 ANYTIME/


DONTFEEL iamworthless ANYTIME

As you guessed, "DONTFEEL " and " ANYTIME" are the strings you would like to crush "iamworthless" with. The "\1" is the variable that stores the entire pattern searched by
the "/\(.*\)/"

No comments: