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 List Installed Packages on Debian
How to Install WordPress with LAMP Stack on Debian 10
How to Install PyCharm on Linux Mint 19
How to Find or Search a Word in Vim or Vi Text Editor
11 Wget Command Examples in Linux (Linux File Downloader)
How to Install Anaconda on CentOS 7
How to Install Ruby on CentOS 7
How to Install Anaconda on Ubuntu 18.04
How to Install Sublime Text 3 on Ubuntu 18.04
How to Install PostgreSQL on Linux Mint 19
How to install PHP 7.2 on Debian 9
How to Disable SELinux on CentOS 8