Javatpoint Logo
Javatpoint Logo

vi Replace All

In command mode, you can replace a string with another string. For this, first you have to type : to move to ex mode. Then select a range of lines from where strings have to be replaced.

If you want to replace a string starting from first line to the last line 1,$ can be uesd. To replace from a particular line mention the starting and last line number. For example, 2,5 will replace from second line to the fifth line.


:<startLine,endLine> s/<oldString>\/<newString>/g

Note: Here g stands for globally. If the string is repeating more than once in a single line, then g is to be used to replace it globally from all the places in the mentioned line range.

Example 1:

:1,$ s/readable/changed/

Linux Vi Replace All1

Look at the above snapshot, we have written the command :1,$ s/readable/changed/

Linux Vi Replace All2

After pressing enter key, string readable is replaced with string changed.

Example 1:

:3,6 s/letters/neww/g

Linux Vi Replace All3

Look at the above snapshot, we have written the command :1,$ s/letters/neww/g

Linux Vi Replace All14

After pressing enter key, string letters is replaced with string neww.

Youtube For Videos Join Our Youtube Channel: Join Now


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Trending Technologies

B.Tech / MCA