These (Linux) VI Editor Shortcuts You Must Know
Last updated
Last updated
VI editor is a powerful text editor that is available on almost all Unix-based systems. Whether you’re a system administrator, DevOps engineer, or developer, mastering VI shortcuts can significantly boost your efficiency. Here are some essential shortcuts every user must know.
VI operates in three primary modes:
Normal mode: Default mode for navigation and editing commands.
Insert mode: Used for inserting text.
Command mode: Used for saving, quitting, and other operations.
h
→ Move left
l
→ Move right
j
→ Move down
k
→ Move up
0
→ Move to the beginning of the line
^
→ Move to the first non-blank character of the line
$
→ Move to the end of the line
w
→ Move forward by a word
b
→ Move backward by a word
gg
→ Move to the beginning of the file
G
→ Move to the end of the file
Ctrl + d
→ Scroll down half a page
Ctrl + u
→ Scroll up half a page
i
→ Insert at cursor position
I
→ Insert at the beginning of the line
a
→ Append after cursor
A
→ Append at the end of the line
o
→ Open a new line below
O
→ Open a new line above
x
→ Delete a character
dw
→ Delete a word
dd
→ Delete the current line
D
→ Delete till the end of the line
yy
→ Copy (yank) a line
p
→ Paste after cursor
u
→ Undo last change
Ctrl + r
→ Redo the last undo
/text
→ Search forward for 'text'
?text
→ Search backward for 'text'
n
→ Repeat the last search in the same direction
N
→ Repeat the last search in the opposite direction
:%s/old/new/g
→ Replace 'old' with 'new' in the entire file
:s/old/new/g
→ Replace all occurrences in the current line
:e filename
→ Open another file
:bn
→ Switch to the next file
:bp
→ Switch to the previous file
:w
→ Save the file
:q
→ Quit VI
:wq
or ZZ
→ Save and exit
:q!
→ Quit without saving
v
→ Start visual selection
V
→ Select an entire line
Ctrl + v
→ Enter visual block mode
>>
→ Indent current line
<<
→ Unindent current line
:set number
→ Show line numbers
:set nonumber
→ Hide line numbers
:set autoindent
→ Enable auto-indentation
:syntax on
→ Enable syntax highlighting
Mastering these VI shortcuts will help you navigate and edit files more efficiently. Whether you’re modifying configuration files or writing scripts, knowing these commands will make your workflow smoother. Start practicing today!