These (Linux) VI Editor Shortcuts You Must Know

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.
1. Modes in VI
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.
2. Navigation Shortcuts
h
→ Move leftl
→ Move rightj
→ Move downk
→ Move up0
→ Move to the beginning of the line^
→ Move to the first non-blank character of the line$
→ Move to the end of the linew
→ Move forward by a wordb
→ Move backward by a wordgg
→ Move to the beginning of the fileG
→ Move to the end of the fileCtrl + d
→ Scroll down half a pageCtrl + u
→ Scroll up half a page
3. Editing Shortcuts
i
→ Insert at cursor positionI
→ Insert at the beginning of the linea
→ Append after cursorA
→ Append at the end of the lineo
→ Open a new line belowO
→ Open a new line abovex
→ Delete a characterdw
→ Delete a worddd
→ Delete the current lineD
→ Delete till the end of the lineyy
→ Copy (yank) a linep
→ Paste after cursoru
→ Undo last changeCtrl + r
→ Redo the last undo
4. Search and Replace
/text
→ Search forward for 'text'?text
→ Search backward for 'text'n
→ Repeat the last search in the same directionN
→ 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
5. Working with Multiple Files
: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
orZZ
→ Save and exit:q!
→ Quit without saving
6. Advanced Commands
v
→ Start visual selectionV
→ Select an entire lineCtrl + 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
Conclusion
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!
Last updated