How to perform Find and Replace using vim Editor


vim is the much-loved text editor when it comes to the command line or the terminal, but it has a learning curve when it comes to performing normal day-to-day operations like find and replace.

Let us take a look at various ways to perform find and replace operation using the:s substitution command,


Find and Replace 1st occurrence in a Line

:/s/sample/example
Find and Replace first occurance
After replace

Find and Replace all occurrences of in a Line

:/s/line/line1/s
Before find and replace line all using vim
after-replace all in line using vim

Find and Replace All occurrences of in a File

:%s/Say/Hello
Before VIM find and Replace all in file
After VIM find and Replace all in file

Facing issues? Have Questions? Post them here! I am happy to answer!

Author Info:

Rakesh (He/Him) has over 14+ years of experience in Web and Application development. He is the author of insightful How-To articles for Code2care.

Follow him on: X

You can also reach out to him via e-mail: rakesh@code2care.org

Copyright © Code2care 2024 | Privacy Policy | About Us | Contact Us | Sitemap