Ultimate Vim Cheat Sheet: Essential Commands and Shortcuts

Table of Contents

Introduction: Why Vim Still Matters

If you have ever found yourself stuck in the Vim editor, desperately mashing the keyboard and Googling "how to exit Vim," you are definitely not alone. Vim's steep learning curve is legendary, but so is its power.

While modern code editors with graphical interfaces are great, mastering Vi and Vim remains a superpower for software engineers, sysadmins, and Linux enthusiasts. It allows you to edit files directly on remote servers, tweak configurations at lightning speed, and completely ditch the mouse to keep your hands on the keyboard.

Yes, the learning curve is steep, but the productivity payoff is massive. To help you master this legendary editor, we have compiled the ultimate, human-readable Vim cheat sheet. Bookmark this page so you never get stuck again!

1. The Absolute Basics: Quick Reference

If you only memorize a handful of commands today, make sure it is these. These are the bread and butter of your daily workflow.

  • i – Enter Insert Mode (start typing)
  • ESC – Return to Command Mode
  • :wq or ZZ – Save and quit
  • :q! – Quit without saving (force quit)
  • dd – Delete the current line
  • yy – Copy (yank) the current line
  • p – Paste
  • u – Undo your last action
  • /text – Search for "text"

2. Opening & File Operations

Before you can edit, you need to know how to handle your files and navigate the terminal environment.

Command Description
vi filenameOpen or create a file
vi -r filenameRecover a crashed file
vi +num fileOpen file directly at a specific line number
:w filenameSave as a new filename
:e filenameEdit another file without leaving Vim
:!lsRun a shell command (like 'ls') from inside Vim

3. Movement & Navigation

Ditch the arrow keys! Vim is designed to keep your fingers on the home row for maximum speed.

Command Description
h, j, k, lMove Left, Down, Up, Right
w / bMove forward / backward by one word
0 or $Jump to the beginning (0) or end ($) of the line
gg / GGo to the very first line / very last line of the file
Ctrl+f / Ctrl+bPage forward / backward one full screen
%Jump to the matching bracket or parentheses

4. Editing: Inserting, Deleting & Changing

Once you are at the right location in your code, you need to manipulate the text efficiently.

Command Description
I / AInsert text at the absolute beginning (I) or end (A) of the line
o / OOpen a new blank line below (o) or above (O) the cursor
dwDelete the current word
d$ or DDelete everything from the cursor to the end of the line
cwChange word (Deletes the word and drops you into Insert Mode)
r / RReplace a single character (r) or enter overwrite mode (R)
~Toggle uppercase/lowercase of the letter under the cursor

5. Search and Replace

Vim's search and replace capabilities are incredibly powerful, using Regex (Regular Expressions) to find exactly what you need.

Command Description
/stringSearch forward for "string"
n / NFind the next occurrence (n) or previous occurrence (N)
*Instantly search for the exact word currently under your cursor
:s/old/new/gReplace all instances of "old" with "new" on the current line
:%s/old/new/gReplace all instances throughout the entire file
:%s/old/new/gcReplace globally, but ask for confirmation before each change

6. Visual Mode & Buffers

Visual mode allows you to highlight blocks of code, while buffers let you juggle multiple files at once.

Command Description
v / VEnter Visual Character mode (v) or Visual Line mode (V)
Ctrl+vVisual Block mode (amazing for editing columns of text/code)
> / <Indent the selected text right (>) or left (<)
:lsList all currently open buffers (files)
:bn / :bpSwitch to the next (:bn) or previous (:bp) buffer

7. Configuration Commands (:set)

Customize how Vim behaves. You can type these during a session, or add them to your .vimrc file to make them permanent.

  • :set nu – Show line numbers
  • :set ic – Ignore case in searches
  • :set ai – Turn on auto-indentation
  • :set syntax on – Turn on syntax highlighting for code

Your Next Steps: Practice!

You cannot learn Vim just by reading a cheat sheet. The muscle memory comes from doing.

Try this exercise today: Open your terminal and type vimtutor. It is a brilliant, interactive 30-minute lesson built directly into Vim that will force you to practice the commands above.

What is your favorite Vim shortcut? Let us know in the comments below!

Frequently Asked Questions (FAQ)

1. How do I exit Vim if I'm stuck?

Press ESC to ensure you're in Command Mode, then type :q! to quit without saving, or :wq to save and quit. Alternatively, ZZ (capital Z twice) saves and quits.

2. What's the difference between Vi and Vim?

Vi is the original Unix text editor. Vim (Vi Improved) is a modern, enhanced clone with features like syntax highlighting, multi-level undo, and a powerful plugin system. Most systems alias vi to vim.

3. How do I undo and redo in Vim?

Use u to undo the last change. To redo (undo an undo), press Ctrl+r.

4. How do I copy, cut, and paste in Vim?

Copy (yank): yy (line) or yw (word). Cut (delete): dd (line) or dw (word). Paste: p (after cursor) or P (before cursor).

5. How do I show line numbers in Vim?

Type :set nu (or :set number) in Command Mode. To make it permanent, add set number to your ~/.vimrc file.

6. How can I learn Vim quickly?

Run vimtutor in your terminal. It's an interactive 30-minute tutorial that comes with Vim and teaches the basics through hands-on exercises.

Comments