Vi Editor Shortcuts: The Complete Cheat Sheet

Vi (short for visual) is a command-line text editor released in 1976 and bundled with virtually every Unix and Linux system. It works through three modes Command, Insert, and Visual and in Command mode almost every key performs an action rather than typing text.

How to save and exit vi: Press Esc, type :wq, and press Enter. To quit without saving, type :q! instead. The shortcut ZZ also saves and exits.

Quick reference (TL;DR):

  • Three modes: Command (default), Insert, Visual
  • Save & exit: :wq or ZZ
  • Quit without saving: :q!
  • Undo: u · Redo: Ctrl + r
  • Full command tables and a free PDF are below.

Note: Vi commands are case-sensitive. A capital letter means Shift + the key, and it usually performs a related but different action from the lowercase version (for example, i and I both start insert mode, but in different positions).

What Is the Vi Editor?

Vi is a modal, command-line text editor created by Bill Joy in 1976 for the Unix operating system. “Modal” means the same key does different things depending on the mode you’re in this is what makes vi fast for experienced users and confusing for beginners.

Because vi is included by default on nearly all Unix and Linux systems, it remains a system administrator’s everyday tool for editing configuration files, scripts, and source code directly in the terminal no mouse required. On most modern systems, typing vi actually launches Vim (“Vi Improved”), a backward-compatible enhanced version released in 1991.

FactDetail
Released1976
CreatorBill Joy
Modes3 (Command, Insert, Visual)
PlatformUnix, Linux, macOS
SuccessorVim (1991)

The Three Vi Modes Explained

Vi behaves differently depending on which mode you’re in. Understanding the modes is the key to everything else most beginner frustration with vi comes from typing commands in the wrong mode.

Command mode (default): When you open a file, vi starts here. Keystrokes are interpreted as commands navigation, deleting, copying not as text. Press Esc at any time to return to Command mode.

Insert mode: Where you actually type text into the file. Enter it with i, a, o, and similar keys. Exit back to Command mode with Esc.

Visual mode: Lets you select blocks of text to copy, delete, or change. Enter with v (character), V (line), or Ctrl + v (block).

In vi, you switch from Command mode to Insert mode to type, and press Esc to switch back to run commands. If vi won’t let you type, you are in Command mode press i to start inserting text.

Starting and Exiting Vi Shortcuts

ActionVi Shortcut
Open or create a filevi filename
Enter command-line (ex) mode:
Write (save):w
Quit:q
Quit without saving:q!
Write and quit:wq
Write and quit (shortcut)ZZ
Quit without saving (shortcut)ZQ
Open another file:e filename
Return to Command modeEsc

Insert Mode Commands

These keys switch you from Command mode into Insert mode so you can type. Remember, lowercase and uppercase do different things.

ActionVi Shortcut
Insert before the cursori
Insert at the start of the lineI
Append after the cursora
Append at the end of the lineA
Open a new line belowo
Open a new line aboveO
Replace single character, then inserts
Replace the whole line, then insertS
Exit Insert modeEsc

Cursor Navigation Shortcuts

All navigation is done in Command mode. Tip: add a number before a command to repeat it (for example, 5j moves down five lines).

ActionVi Shortcut
Move lefth
Move down one linej
Move up one linek
Move rightl
Start of next wordw
Start of previous wordb
End of current worde
Start of the line0 (zero)
First non-blank character of line^
End of the line$
Top of the documentgg
Bottom of the documentG
Go to a specific line number:n (e.g., :10)

Deleting and Cutting Text shortcuts

In vi, deleting text also cuts it to a buffer, so you can paste it back with p.

ActionVi Shortcut
Delete character under cursorx
Delete character before cursorX
Delete a worddw
Delete to end of lineD
Delete the current linedd
Delete and re-enter insert (change line)cc
Delete a word and insertcw

Copy and Paste (Yank and Put) shortcuts

Copying in vi is called yanking, and pasting is called putting.

ActionVi Shortcut
Yank (copy) a wordyw
Yank (copy) the current lineyy or Y
Put (paste) after the cursorp
Put (paste) before the cursorP

Undo and Redo shortcuts

ActionVi Shortcut
Undo the last changeu
Undo all changes on the current lineU
Redo (Vim)Ctrl + r
Repeat the last command.

Search and Replace shortcuts

Searching and replacing are done from Command mode.

To search:

ActionVi Shortcut
Search forward for a term/term
Search backward for a term?term
Repeat search in same directionn
Repeat search in opposite directionN

To find and replace, use the substitute command:

  1. Press Esc to make sure you’re in Command mode.
  2. Type the substitute command and press Enter.
ActionVi Shortcut
Replace first match on current line:s/old/new/
Replace all matches on current line:s/old/new/g
Replace all matches in the whole file:%s/old/new/g
Replace all, asking for confirmation:%s/old/new/gc

Visual Mode Shortcuts

Visual mode lets you highlight text first, then act on it.

ActionVi Shortcut
Start character-wise selectionv
Start line-wise selectionV
Start block (column) selectionCtrl + v
Yank (copy) the selectiony
Delete the selectiond
Change the selectionc
Exit Visual modeEsc

Useful Configuration Settings

Type these in Command mode (they apply to your current session).

ActionVi Shortcut
Show line numbers:set number
Hide line numbers:set nonumber
Case-insensitive search:set ignorecase
Turn on syntax highlighting (Vim):syntax on
Show current settings:set all

Download the Vi Shortcuts PDF

Want an offline copy to keep next to your keyboard? Download the Vi Shortcuts Cheat Sheet PDF.

Frequently Asked Questions

How do I exit vi?

Press Esc, then type :q to quit, :wq to save and quit, or :q! to quit without saving. You can also press ZZ to save and exit.

How do I save a file in vi?

Press Esc to enter Command mode, then type :w and press Enter to save without exiting, or :wq to save and quit.

Why won’t vi let me type?

You are in Command mode, where keys act as commands. Press i to enter Insert mode, and then you can type normally. Press Esc to return to Command mode.

How do I delete a line in vi?

In Command mode, place the cursor on the line and press dd. To delete multiple lines, type a number first for example, 3dd deletes three lines.

How do I copy and paste in vi?

Press yy to copy (yank) the current line, then move the cursor and press p to paste after it or P to paste before it.

How do I search and replace in vi?

Press Esc, then type :%s/old/new/g and press Enter to replace every occurrence of old with new throughout the file.

What is the difference between vi and vim?

Vi is the original editor from 1976; Vim is an improved version from 1991 with multiple undo, syntax highlighting, and split windows. On most systems, vi launches Vim.

Is vi still used in 2026?

Yes. Vi (usually as Vim) remains pre-installed on virtually all Unix and Linux systems and is widely used by system administrators and developers for fast terminal-based editing.

Conclusion

Vi rewards a little memorization with a lot of speed. You don’t need every command on day one start with the essentials: i to insert, Esc to get back to Command mode, and :wq to save and exit. Once those feel automatic, layer in navigation (h j k l, gg, G), editing (dd, yy, p), and search-and-replace (:%s/old/new/g). Within a week of daily use, the modes stop feeling awkward and start feeling faster than any mouse-driven editor.

Read next:

Pratik

Pratik is the founder of Tutorial Tactic and a productivity tools specialist with 15 years of hands-on experience in Google Workspace, Microsoft Office, and software automation. He has published over 1,500 guides on keyboard shortcuts, software commands, how-to tutorials and workflow optimization, helping readers across the US and India work faster with the tools they use every day. Tutorial Tactic was founded in 2021 with one goal: cut through the noise and give readers exactly what they need fast, verified, and beginner-friendly.
Back to top button