Search and Replace
To find and replace words in the vim editor we use substitute or:s command syntax of the command is as follows:
:[range]s/{pattern}/{string}/[flags] [count]
The command searches the pattern in [range] lines and replaces the [pattern] with [string]. If [range] is not mentioned then the command will replace the words in the current line with [string] only.
Example:
Basic Vim Commands
In this article, we will cover some basic commands in the Vim editor. First, we look at what Linux and VIM editors are and why we use them, followed by basic commands in Vim editor starting from creating/editing a file, different modes, quitting the editor, saving the changes to the file, navigation in the editor, deleting lines, displaying and hiding line numbers, search and replace, and syntax highlighting along with the syntax of commands and screenshots.
Linux
Linux was developed by Linus Torvalds in 1991 as a hobby project. It is an open-source (source code that can be used by anyone freely) kernel that is most popular and widely used in the industry as well as in personal systems. There are various operating systems based on the Linux kernel, some of the popular Linux distributions are Ubuntu, CentOS, Red Hat, Debian, and Kali Linux.
VIM Editor
Vi Editor is a widely used text editor in Unix/Linux systems and is known for its efficiency and flexibility. Vi editor was developed in 1976 by Bill Joy and later in 1991, an improved version of Vi editor was released which is known as VI Improved (VIM).
Basic VIM Commands
- 1. Create/Edit a file
- 2. Changing modes in the Vim editor
- 3. Quit the Vim editor
- 4. Save the changes
- 5. Navigation in Vim editor
- 6. Delete a line
- 7. Search and Replace
- 8. Display Line Numbers
- 9. Hide Line numbers
- 10. Syntax Highlighting