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?
Vi commands
Let’s see the commands that are used in the vi editor.
Command | Description |
---|---|
:wq or ZZ | Save and quit editor |
:q! | Quit without saving |
yy | Yank (copy) the selected line |
p | Paste a line of yanked (copied) text |
o | Opens a new line under the current line |
0 (zero) | Opens a new line above the current line |
A | Append text at the end of the current line |
a | Append text after the cursor’s current position |
I | Insert text at the beginning of the current line |
b | Go to the beginning of the current word relative to the cursor’s position |
e | Go to the end of the current word relative to the cursor’s position |
x | Delete a single character preceding the cursor |
dd | Delete the entire active line |
Xdd | Delete multiple lines after the cursor. X denotes the number of lines |
Xyy | Yank (copy) multiple lines following the cursor. X denotes the number of lines |
G | Jump to the last line in a file |
XG | Jump to a specific line. X denotes the line number. |
gg | Jump to the first line in a file |
:num | Display the active line’s line number |
h | Move one character to the left of the cursor |
j | Move one character under the cursor |
k | Move one character above the cursor |
l | Move one character to the right of the cursor |
(With inputs from Chetali Shah)
Also read: How to delete lines in Vim?