Vi(m) Editor Flashcards
The three vi editor modes
command mode, insert mode, and ex mode
In command mode, this is how you move the cursor one character to the right.
l (lowercase L)
In command mode, this is how you move the cursor one character to the left.
h
In command mode, this is how you move the cursor down one line.
j (lowercase)
In command mode, this is how you move the cursor up one line.
k (lowercase)
It means to yank in the vi editor
“Copy (yank) a line”
In command mode, this is how you copy an entire line that the cursor is currently on.
yy
In command mode, this is how you copy the current line that the cursor is on, as well as the line beneath the current line (2 lines total).
2yy
In command mode, this is how you copy the current line and a certain amount of additional lines.
yy, where # includes the current line and however many other lines wished to be copied.
In command mode, this is how you paste the contents from a yank/copy, pasting it on the line after your cursor.
p (lowercase)
In command mode, this is how you paste the contents from a yank/copy, pasting it on the line before your cursor.
P (uppercase)
In command mode, this is how you move the cursor to a specific line #.
G or #gg
In command mode, this is how you move the cursor to the beginning of the last line in the file.
G
In command mode, this is how you move the cursor to the first line on the terminal screen.
1G
In command mode, this is how you move the cursor to the last line on the terminal screen.
L
In command mode, this is how you move the cursor to the first line on the terminal screen.
H
In command mode, this is how you start insert mode and create a new line below the current cursor position, using one command.
o (lowercase O)
In command mode, this is how you undo movement or yanks or any command entered in command mode.
u (lowercase u)
In command mode, this is how you remove the current word the cursor is at and start insert mode, changing that text.
cc (lowercase)
In command mode, this is how you search the file for a forward occurrence of what you are searching for.
/termhere
In command mode, this is how you move to the next (forward/backward) occurrence of a searched term in the direction being searched.
n
In command mode, this is how you search backwards, before the current cursor location.
?termhere
In command mode, this is how you search backwards, before the current cursor location.
?termhere
This is how you start insert mode to begin adding new text.
i, in command mode
This is how you start insert mode with it set to overwrite old text.
R, in command mode
This is how you start insert mode by removing the word the cursor is at and then being able to add new text.
cw, in command mode
This is how you start insert mode to erase a line of text and then be able to insert new text.
cc, in command mode
This is how you start ex mode.
”:” while in command mode
This is how you replace the first occurrence of a word with another word.
:%s/example/new (from command mode)
This is how you replace all occurrences of a word with another word.
:%s/example/new/g, where g stands for global (from command mode)
This is how you save changes without exiting?
:w (from command mode)
This is how you save changes and quit the vi editor (two possible ways).
:wq or ZZ (both from command mode)
This is how you quit without saving changes.
:q (from command mode)
This is how you load a new file to edit in vi editor. For it to work, you have to save your current file first.
:e /file.txt (from command mode)
This is how you bring contents of an old file into a new one.
:r (from command mode)
This is how you run shell commands from within the vi editor, example using the “ls /etc” command.
:!ls /etc (from command mode)
This is how you get to command mode from insert mode.
ESC
In command mode, this is how you delete a word.
dw
In command mode, this is how you delete the character the cursor is on.
X (uppercase)
In command mode, this is how you delete the entire current line and a certain amount of lines below the current line as well.
dd
In command mode, this is how you delete the entire current line.
dd
In command mode, this is how you delete more than one word from the current cursor.
dw
In command mode, this is how you move the cursor to the beginning of the current line.
0 (zero)
In command mode, this is how you refresh the document to the original state that you started editing it in without any changes made.
:e! (from command mode)
In command mode, this is how you make line numbers visible.
:set nu (from command mode)
In command mode, this is how you remove line numbers from being visible.
:set nonu (from command mode)
In command mode, this is how you start insert mode where the new text starts AFTER the current cursor position.
a