How to Search and Replace Text in Vim or Vi
Table of Contents
Find and Replace Text in Vim or Vi
Vim is a popular text editor among the system administrators and developers. On most of the Linux Distros, it comes preinstalled. We can edit code in Vim easily by using the different shortcuts. In this tutorial, you are going to learn how to Search and Replace Text in Vim or Vi.
Basic Syntax for Find and Replace in Vim
Following is the basic syntax for Find and Replace in Vim:
In the above syntax,
SEARCH_TEXT: Text to search.
REPLACE_TEXT: Text to replace.
COMMAND_FLAG: Different flags used when search and replace.
1. Search and Replace Words in Current
You can replace all the occurrence of the specific word on the current line using below command:
2. Search and Replace Words on All Lines
You can replace all the occurrence of the specific word on all the lines using below command:
3. Search and Replace Case-Sensitive Words
By using the
i flag we can replace case-sensitive words. You can use following command to Search and Replace Case-Sensitive words.
4. Search and Replace Words Between Specific Lines Range
You can also search and replace words between the specific line number range by using the following command:
4. Find and Replace Words Asking Confirmation
By using the
c flag we ask for confirmation before replacing text.
In this tutorial, you have learned how to Search and Replace Text in Vim or Vi. If You have any queries regarding this please comment below.
- How to Install Apache Tomcat 9 on Debian 9
- Easily Quit Vim/Vi Without Saving Changes Command
- How to Install PostgreSQL on Ubuntu 18.04
- How To Secure Nginx with Let’s Encrypt SSL on Debian 9
- How to migrate MySQL database between two servers
- How to Install Sublime Text 3 on Debian 10
- How to Install Yarn on Debian 9
- How to Install RubyMine on Ubuntu 18.04
- How to Install Pip on Linux Mint 19
- How to Create New User and Grant Permissions in MySQL
- How to Use Shutdown Command in Linux
- How to Install PyCharm on Manjaro 18