Find and Replace in VIM Editor

Suppose we have a text file from which we want to search for string “hello” and replace it with “hi” , then below commands shows how to do find and replace in vim editor for different scenarios.

Search for First Occurrence in a Single Line and Replace it.

Go to the line from which we need to find and replace first occurance and type below,

:s/hello/hi/

So, for example if we have a line “say hello hello !” then above command will make it as “say hi hello!”

Search for All Occurrences in a Single Line and Replace it.

Just pass, “g” at the end of command used for replacing first occurrence.

:s/hello/hi/g

So, for example if we have a line “say hello hello !” then above command will make it as “say hi hi!”

How to remove index.php from URL in... x
How to remove index.php from URL in CodeIgniter using .htaccess

Leave a Comment

Sign up to our newsletter!

ADB Commands Android Android Applications Android Build system Application Libraries Application Stack / User Interface Bash / Shell Scripts Bluetooth driver Cloud Technologies Commands and Packages Compilation Content Management System Core Kernel C Programs Development, Debugging and Performance Tools Development and Build Development Environment Setup Django & REST Api Errors & Failures Git Hardware Platforms HTML JAVA Programs Linux, OS Concepts and Networking Linux Device Drivers Linux Host, Ubuntu, SysAdmin Linux Kernel Linux Networking Middleware Libraries, HAL Multimedia NDK / Middleware / HAL Operating System Concepts PHP Programming Languages Scripting and Automation Search Engine Optimisation ( SEO ) Social Media Source Code Management ( SCM ) System Administration, Security Testing and Debugging Uncategorized Web Design and Development Website Hosting Wordpress Yocto Embedded Linux