Essential VI Editor Techniques for Efficient Text Editing in Linux

2 min readMar 12, 2025

Basic Modes in VI

  1. Normal Mode — Default mode for navigation and commands.
  2. Insert Mode — For editing text (press i or a to enter).
  3. Visual Mode — For selecting text (press v to enter).
  4. Command Mode — For saving, quitting, and other commands (press : to enter).

Essential Commands

Opening & Exiting VI

  • vi filename → Open a file in vi.
  • :q → Quit (if no changes were made).
  • :q! → Quit without saving changes.
  • :w → Save the file.
  • :wq or ZZ → Save and exit.

Navigation

  • h → Move left
  • l → Move right
  • j → Move down
  • k → Move up
  • w → Jump forward by a word
  • b → Jump backward by a word
  • 0 → Go to the beginning of the line
  • $ → Go to the end of the line
  • gg → Go to the start of the file
  • G → 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 cursor
  • a → Insert mode after cursor
  • o → Open a new line below and enter insert mode
  • O → Open a new line above and enter insert mode
  • r → Replace one character
  • x → Delete one character
  • dd → Delete (cut) the whole line
  • yy → Copy (yank) the whole line
  • p → Paste after cursor
  • P → Paste before cursor

Search & Replace

  • /word → Search forward for "word"
  • ?word → Search backward for "word"
  • n → Repeat last search forward
  • N → 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 change
  • Ctrl + r → Redo the last undo
  • . → Repeat the last command
  • V → Enter Visual Line Mode (select whole lines)
  • Ctrl + d → Scroll half-page down
  • Ctrl + u → Scroll half-page up
  • :set number → Show line numbers
  • :set nonumber → Hide line numbers

--

--

Umar Farooque Khan
Umar Farooque Khan

Written by Umar Farooque Khan

Experienced software developer with a passion for clean code and problem-solving. Full-stack expertise in web development. Lifelong learner and team player.

No responses yet