Find and Replace VIM Command

How to use Find and Replace Command in Linux VIM editor?

Explanation


:%s/text1/text2/g stands for Find and replace
This command is used to find and replace a string. In the above command, text1 is the string to find and text2 is the string to be replaced.

Usage:

:%s/text1/text2/g

Example:

  • Open the file test.txt using the command
    $ vim test.txt
  • We can notice the text in the file.
    Hiox India
    Vim Tutorial

  • In this file let us replace the word 'India' as 'Software'. To replace the string enter.
    Enter :%s/India/Software/g
  • The text after the replacement will be as follows,
    Find and Replace Vim Command

Ask Questions

Ask Question