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.
| Fact | Detail |
|---|---|
| Released | 1976 |
| Creator | Bill Joy |
| Modes | 3 (Command, Insert, Visual) |
| Platform | Unix, Linux, macOS |
| Successor | Vim (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
| Action | Vi Shortcut |
|---|---|
| Open or create a file | vi 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 mode | Esc |
Insert Mode Commands
These keys switch you from Command mode into Insert mode so you can type. Remember, lowercase and uppercase do different things.
| Action | Vi Shortcut |
|---|---|
| Insert before the cursor | i |
| Insert at the start of the line | I |
| Append after the cursor | a |
| Append at the end of the line | A |
| Open a new line below | o |
| Open a new line above | O |
| Replace single character, then insert | s |
| Replace the whole line, then insert | S |
| Exit Insert mode | Esc |
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).
| Action | Vi Shortcut |
|---|---|
| Move left | h |
| Move down one line | j |
| Move up one line | k |
| Move right | l |
| Start of next word | w |
| Start of previous word | b |
| End of current word | e |
| Start of the line | 0 (zero) |
| First non-blank character of line | ^ |
| End of the line | $ |
| Top of the document | gg |
| Bottom of the document | G |
| 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.
| Action | Vi Shortcut |
|---|---|
| Delete character under cursor | x |
| Delete character before cursor | X |
| Delete a word | dw |
| Delete to end of line | D |
| Delete the current line | dd |
| Delete and re-enter insert (change line) | cc |
| Delete a word and insert | cw |
Copy and Paste (Yank and Put) shortcuts
Copying in vi is called yanking, and pasting is called putting.
| Action | Vi Shortcut |
|---|---|
| Yank (copy) a word | yw |
| Yank (copy) the current line | yy or Y |
| Put (paste) after the cursor | p |
| Put (paste) before the cursor | P |
Undo and Redo shortcuts
| Action | Vi Shortcut |
|---|---|
| Undo the last change | u |
| Undo all changes on the current line | U |
| Redo (Vim) | Ctrl + r |
| Repeat the last command | . |
Search and Replace shortcuts
Searching and replacing are done from Command mode.
To search:
| Action | Vi Shortcut |
|---|---|
| Search forward for a term | /term |
| Search backward for a term | ?term |
| Repeat search in same direction | n |
| Repeat search in opposite direction | N |
To find and replace, use the substitute command:
- Press Esc to make sure you’re in Command mode.
- Type the substitute command and press Enter.
| Action | Vi 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.
| Action | Vi Shortcut |
|---|---|
| Start character-wise selection | v |
| Start line-wise selection | V |
| Start block (column) selection | Ctrl + v |
| Yank (copy) the selection | y |
| Delete the selection | d |
| Change the selection | c |
| Exit Visual mode | Esc |
Useful Configuration Settings
Type these in Command mode (they apply to your current session).
| Action | Vi 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:





