Config file modification in VI

I often need to change config files in VI, unfortunately many times in an obvious violation of DRY: we copy/paste a section of the config file, then replace a string inside the pasted section with something else. While the copy-and-paste-then-modify practice is not ideal in general, here is a way to make it a little easier and safer. This uses a sed command from within vi.


vi file.conf
...
(esc)20yy 
(esc)p
:.,.+20s/old_string/new_string/g
...