Find and Replace in Vim Editor |
We can easily find and replace match word in vim text editor, it is very useful if we have multiple same value and we want to change/replace with other value, below are the steps
Open a file which you want to find and replace the text
vi /tmp/lokesh
Explanation:
:%s/lokesh/administratoror:%s/lokesh/administrator/g
1 - We switch command mode by pressing the Esc and Colon ( : )
2 - We will type %s for search string and then type /lokesh , means we are find lokesh word in the file, then we will type word which we want to replace like /administrator
3 - /g, while the g stands for global, which means that all matching occurrences in the line would be replaced.
To find and replace in vi editor with confirmation
We used only c for the confirmation, means it will ask you for every match word to replace, we will provide confirmation by pressing Y for yes or N for skip the replace. below screenshot
:%s/lokesh/administrator/gc
Thanks you !!
I hope this topic gave you all the information you needed. If you have any further questions or would like more detailed directions feel free to contact us using any of the following sources.We look forward to talking to you.