10. Find & replace
With this type of vi editor commands we can find & replace the contents of the file.
- :1,$ s/<old>/<new>/g ===> replace the character or word in the whole file
where 1 denotes first line & $ denotes last line
- :% s/<old>/<new>/g ===> Same as above
- :1,. s/<old>/<new>/g ===> replace the character or word between the lines
where 1 denotes first line & . denotes current cursor position
- :@,. s/<old>/<new>/g ===> replace the character or word between the lines
where @ denotes line number & . denotes current cursor position
- eg.
- :3,. s/new/new1/g ===> will replace all the word “new”with “new1″between the lines 3rd till current cursor position
- :.,$ s/<old>/<new>/g ===> replace the character or word between the lines
where. denotes current cursor position & $ denotes last line
- :.,@ s/<old>/<new>/g ===> replace the character or word between the lines
where. denotes current cursor position & @ denotes line number
- :@,@ s/<old>/<new>/g ===> replace the character or word between the lines
where @ denotes line number
Leave a Reply