Display Line Numbers
To display absolute line numbers use any of the following commands,
Syntax:
:set number
or
:set nu
Example/Screenshot:
To display relative line numbers: In relative line numbers the current line is shown as 0 and the lines above and below are incremented by 1,
Syntax:
:set relativenumber
or
:set rnu
Example/Screenshot:
We have covered a detailed article on this at GFG which you can check out here.
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