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
-


Have Questions? Post them here!


Top Hashtags: