Replacing in vi editor
To find and replace word in vi editor we use :substitute or :s command syntax of the command is as follows:
:[range]s/{pattern}/{string}/[flags] [count]
The command searches the pattern in [range] lines and replace the [pattern] with [string]. If [range] is not mentioned then command will replace the words in the current line with [string] only.
Example – :s/was/were
You have noticed that the previous command only replace one occurence of the [word] if you want to replace all the occurences of the word add g flag in the command,
Example – :s/was/were/g
Mastering Search and Replace in Vi Editor
Vi Editor, a powerful text editor renowned for its efficiency and versatility, is a staple tool for Unix/Linux users. Mastering its search and replace functionalities can significantly enhance productivity and streamline text editing tasks. In this comprehensive guide, we will delve into various techniques and strategies to effectively search for and replace text within Vi Editor, empowering users to harness its full potential.
Table of Content
- Understanding VI Editor
- Searching in vi editor
- Replacing in vi editor
- To replace all occurences in file Using Vi Editor
- Replace the word within the given range in Vi Editor
- Ignore case sensitivity in Vi Editor
- How to Search and Replace in Vi Editor – FAQs
Contact Us