Vi is the default text editor with the Linux system, and vi is the visual editor. Vi is a common text editor in almost every Linux system. This article would be a cheat sheet for you to refer to whenever you want to use the vi editor.
Also read: How to save and exit in Vim?
Basics of the vi editor
The vi editor has two modes of operation:
- Command Mode: The command mode is the mode where you specify what action you want to implement on your file.
- Insert Mode: The insert mode is where you insert the data into your file.
You can open or create a new file in the vi editor by simply using the command given below.
vi <file name>
You can press ESC followed by the colon “:” to go into the command mode.
You can press ‘i’ to go into the insert mode.
Vi vs Vim
An important thing to note is the difference between Vi and Vim. Vi is the base editor, while Vim stands for “Vi Improved” and is an enhanced version of the editor with additional features.
On most Linux distributions, Vi and Vim are interchangeable. If you try and launch Vi, you’ll likely end up in Vim. However, some distributions still require users to manually install Vim if they want to use the enhanced editor.
Also read: How to undo/redo in Vim?
Let’s see the commands that are used in the vi editor.
|:wq or ZZ
|Save and quit editor
|Quit without saving
|Yank (copy) the selected line
|Paste a line of yanked (copied) text
|Opens a new line under the current line
|Opens a new line above the current line
|Append text at the end of the current line
|Append text after the cursor’s current position
|Insert text at the beginning of the current line
|Go to the beginning of the current word relative to the cursor’s position
|Go to the end of the current word relative to the cursor’s position
|Delete a single character preceding the cursor
|Delete the entire active line
|Delete multiple lines after the cursor. X denotes the number of lines
|Yank (copy) multiple lines following the cursor. X denotes the number of lines
|Jump to the last line in a file
|Jump to a specific line. X denotes the line number.
|Jump to the first line in a file
|Display the active line’s line number
|Move one character to the left of the cursor
|Move one character under the cursor
|Move one character above the cursor
|Move one character to the right of the cursor
(With inputs from Chetali Shah)
Also read: How to delete lines in Vim?