Essential VI Editor Techniques for Efficient Text Editing in Linux
2 min readMar 12, 2025
Basic Modes in VI
- Normal Mode — Default mode for navigation and commands.
- Insert Mode — For editing text (press
i
ora
to enter). - Visual Mode — For selecting text (press
v
to enter). - Command Mode — For saving, quitting, and other commands (press
:
to enter).
Essential Commands
Opening & Exiting VI
vi filename
→ Open a file invi
.:q
→ Quit (if no changes were made).:q!
→ Quit without saving changes.:w
→ Save the file.:wq
orZZ
→ Save and exit.
Navigation
h
→ Move leftl
→ Move rightj
→ Move downk
→ Move upw
→ Jump forward by a wordb
→ Jump backward by a word0
→ Go to the beginning of the line$
→ Go to the end of the linegg
→ Go to the start of the fileG
→ Go to the end of the file:n
→ Jump to line n (e.g.,:10
goes to line 10)
Editing Text
i
→ Insert mode before cursora
→ Insert mode after cursoro
→ Open a new line below and enter insert modeO
→ Open a new line above and enter insert moder
→ Replace one characterx
→ Delete one characterdd
→ Delete (cut) the whole lineyy
→ Copy (yank) the whole linep
→ Paste after cursorP
→ Paste before cursor
Search & Replace
/word
→ Search forward for "word"?word
→ Search backward for "word"n
→ Repeat last search forwardN
→ Repeat last search backward:%s/old/new/g
→ Replace all occurrences of "old" with "new":10,20s/old/new/g
→ Replace "old" with "new" only from line 10 to 20
Advanced Tricks
u
→ Undo the last changeCtrl + r
→ Redo the last undo.
→ Repeat the last commandV
→ Enter Visual Line Mode (select whole lines)Ctrl + d
→ Scroll half-page downCtrl + u
→ Scroll half-page up:set number
→ Show line numbers:set nonumber
→ Hide line numbers