How to replace words using VI editor on the fly

HI Guys,

How Can I replace particular words in a file starting from the line where my cursor is pointing while the file is opened in VI editor?

If you are using sed, please give me the code.

Thanks

press escape to switch in command mode then

:45,66s/toto/titi/g

will replace toto by titi from line 45 to line 66
g = in a global manner (if toto appear more than once in a line, it get also replaced by titi)

to replace in a whole file use % :
to ask confirmation before replacement, use c , see below

:%s/toto/titi/gc

then

:wq! 

... in order to save your modifications

1 Like

_TYVM_