vi Replace AllIn 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. Syntax: :<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/ ![]() Look at the above snapshot, we have written the command :1,$ s/readable/changed/ ![]() After pressing enter key, string readable is replaced with string changed. Example 1: :3,6 s/letters/neww/g ![]() Look at the above snapshot, we have written the command :1,$ s/letters/neww/g ![]() After pressing enter key, string letters is replaced with string neww.
Next TopicLinux vi Text buffers
|