My previous question seems to be a bit ambiguous, I will rephrase it:
I have a file like this:
copythis abc replacethis1 xyz qwerty replacethis2 hasfshd replacethis3 fslfs And so on...
NOTE: replacethis1, replacethis2, replacethis3, … could be any words
How do I replace ‘replacethis1′,’replacethis2′,’replacethis3’,.. word by ‘copythis’ word by using minimum vim commands.
One way I can do is by these steps:
- delete ‘replacethis1′,’replacethis2′,’replacethis3’,.. by using ‘dw’
- copy ‘copythis’ using ‘yw’
- move cursor to where ‘replacethis1’ was and do ‘p’; move cursor to where ‘replacethis2’ was and do ‘p’ and so on…
Is there a better way to do this in VIM (using less number of vim commands)?
Since you changed your question, I’d do it this way:
Move to the first ‘replacethis1’ and type cw (change word), then type ‘copythis’ manually.
Move to the next ‘replacethis’, hit . (repeat last operation)
Move to the next ‘replacethis’, hit .,
and so on, and so on.
If ‘copythis’ is a small word, I think this is the best solution.