Creating a File in Vim
Firstly, we will create a file that we will use throughout the article to perform searching and replacing. It is easy enough to create a file in Vim, you just have to run the Vim command and pass the filename as an argument.
vim <filename>
We will create a file named geek for this tutorial.
vim geek
This will open the Vim editor and will look like the following:
Now, to type in the content, we will type ‘i’ in the command mode(which is the default mode). This will allow us to write content into the geek file. The content we are using is as follows;
Howdy!
This is a document.
This is made for w3wiki.
Keep geeking!
Once, you have written this content into the file, you need to save it. To do this, you need to switch back to command mode, which can be done by pressing the ESC button. Once, you are in command mode, type the following command and press Enter:
:wq!
This will save your work.
Now, we can move to searching and replacing part of the tutorial.
Searching and Replacing in Vim Editor
Vim is an excellent version of the legacy Vi editor for terminals. It is a complete command line-based text editor that has been the go-to choice for IT professionals for decades. Vim is the Vi-IMproved version of the original text editor which contains many modern features. In this article, we shall explore one such feature, the functionality to search and replace in a file. We will see various methods of searching and replacing based on different criteria such as letter case, regular expressions, etc.