Vim has a reputation for being impossible to learn. The meme writes itself: "How do I exit Vim?" But every developer who pushes through the initial curve eventually says the same thing — "I can't go back."
The reason is simple: Vim is a language for editing text. Once you learn its grammar, you compose commands the way you compose sentences. You stop thinking about the editor and start thinking about the code.
This guide skips the basics you already know (hjkl, :wq) and jumps straight to the habits and techniques that make experienced Vim users faster than everyone else in the room.
The Mental Model: Operator + Motion
Every Vim command follows this pattern:
[count] [operator] [motion]
-
Operator: what to do (
ddelete,cchange,yyank,vselect) -
Motion: what to act on (
wword,$end of line,}next paragraph) - Count: how many times
Examples:
d3w → delete 3 words
c$ → change from cursor to end of line
y} → yank to next paragraph
>G → indent from here to end of file
=ap → auto-indent current paragraph
Once this clicks, you stop memorizing commands and start composing them.
Navigation (Move Without Your Hands Leaving the Keyboard)
Within a Line
0 → start of line (before whitespace)
^ → first non-blank character
$ → end of line
f{c} → jump to next occurrence of character c
F{c} → jump backward to character c
t{c} → jump just before next occurrence
; → repeat last f/t/F motion
, → repeat in reverse
Between Lines
gg → top of file
G → bottom of file
5G → go to line 5
Ctrl-d → scroll down half page
Ctrl-u → scroll up half page
Ctrl-f → scroll down full page
Ctrl-b → scroll up full page
zz → center current line on screen
zt → scroll so current line is at top
zb → scroll so current line is at bottom
By Pattern
/search → search forward (n for next, N for previous)
?search → search backward
* → search for word under cursor (forward)
# → search for word under cursor (backward)
% → jump to matching bracket/paren/brace
Jump List
Ctrl-o → jump back to previous location
Ctrl-i → jump forward
:jumps → show jump list
Text Objects (The Most Underused Feature)
Text objects let you operate on semantic units — words, sentences, blocks, HTML tags. They work with any operator.
iw → inner word (the word itself)
aw → a word (word + surrounding space)
is → inner sentence
as → a sentence
ip → inner paragraph
ap → a paragraph
i" → inner double quotes (text between " ")
a" → double quotes + surrounding whitespace
i' → inner single quotes
i` → inner backticks
i( → inner parentheses
a( → including the parens
i{ → inner curly braces
i[ → inner square brackets
it → inner HTML/XML tag
at → including the tag itself
Real-world examples:
ci" → change text inside double quotes (keep the quotes)
da( → delete including the parentheses
yi{ → yank everything inside braces
vit → visually select text inside HTML tag
=i{ → auto-indent inside the current block
Once you have text objects, editing becomes surgical.
Insert Mode Tricks
Most developers stay in insert mode too long. These shortcuts let you edit without leaving it:
Ctrl-w → delete word before cursor
Ctrl-u → delete line before cursor
Ctrl-r " → paste from unnamed register
Ctrl-r + → paste from system clipboard
Ctrl-t → indent current line
Ctrl-d → un-indent current line
Ctrl-n → autocomplete next word
Ctrl-p → autocomplete previous word
Registers: Copy/Paste on Steroids
Vim has 26 named registers (a–z) plus several special ones.
"ayy → yank line into register a
"ap → paste from register a
"byiw → yank word into register b
" → unnamed (default) register
0 → yank register (last yank)
+ → system clipboard
* → primary selection (Linux/macOS)
/ → last search pattern
: → last command
. → last inserted text
% → current filename
:reg → view all registers
"+yy → yank line to system clipboard
"+p → paste from system clipboard
Pro tip: Get in the habit of using "0p instead of p after a delete. It always pastes your last yank, not whatever was last deleted.
Macros: Automate Repetitive Edits
Macros record a sequence of keystrokes and replay them.
qa → start recording into register a
[do your edits]
q → stop recording
@a → replay macro a
@@ → replay last macro
10@a → replay 10 times
Real example: Add a semicolon to the end of every line in a range:
qa → start recording
A;Escape → append semicolon, leave insert mode
j → move down
q → stop recording
50@a → run on next 50 lines
Or use :normal for a visual selection:
:'<,'>normal A; → append ; to every selected line
Global Commands (Operate on Many Lines at Once)
:g/pattern/command → run command on all matching lines
:g!/pattern/command → run on non-matching lines
# Examples:
:g/console.log/d → delete all console.log lines
:g/TODO/normal I# → add # to start of every TODO line
:g/^$/d → delete all blank lines
:v/import/d → delete all lines that DON'T contain "import"
Marks: Bookmarks in Your File
ma → set mark a at current position
'a → jump to line with mark a
`a → jump to exact position of mark a
'' → jump back to last jump position
`. → jump to last edit location
:marks → list all marks
Capital marks (A-Z) work across files — a global bookmark that persists across sessions.
Windows, Tabs, and Buffers
# Buffers (open files)
:ls → list open buffers
:b3 → switch to buffer 3
:b name → switch to buffer by name
:bn / :bp → next / previous buffer
:bd → close buffer
# Splits
:split / :sp → horizontal split
:vsplit / :vs → vertical split
Ctrl-w h/j/k/l → navigate between splits
Ctrl-w = → equalize split sizes
Ctrl-w _ → maximize current split height
Ctrl-w | → maximize current split width
# Tabs
:tabnew → new tab
gt / gT → next / previous tab
:tabclose → close tab
Neovim: Why You Should Switch
Neovim is a modernized fork of Vim with:
- Lua config (faster and more readable than Vimscript)
- Built-in LSP (Language Server Protocol for IDE-like intelligence)
- Tree-sitter (accurate syntax highlighting)
- Async job control (plugins don't block editing)
Minimal Neovim Config (~/.config/nvim/init.lua)
-- Set leader key
vim.g.mapleader = " "
-- Line numbers
vim.opt.number = true
vim.opt.relativenumber = true
-- Tabs/indentation
vim.opt.tabstop = 2
vim.opt.shiftwidth = 2
vim.opt.expandtab = true
-- Search
vim.opt.ignorecase = true
vim.opt.smartcase = true
-- Appearance
vim.opt.wrap = false
vim.opt.scrolloff = 8
-- System clipboard
vim.opt.clipboard = "unnamedplus"
-- Key mappings
vim.keymap.set("n", "<leader>e", ":Explore<CR>")
vim.keymap.set("n", "<leader>w", ":w<CR>")
vim.keymap.set("n", "<leader>q", ":q<CR>")
vim.keymap.set("n", "<Esc>", ":noh<CR>") -- clear search highlights
Essential Plugin Ecosystem
| Plugin | Purpose |
|---|---|
lazy.nvim |
Plugin manager |
telescope.nvim |
Fuzzy finder (files, grep, buffers) |
nvim-lspconfig |
LSP integration |
nvim-cmp |
Autocompletion |
nvim-treesitter |
Syntax highlighting |
gitsigns.nvim |
Git blame/diff in the gutter |
which-key.nvim |
Key binding help popup |
oil.nvim |
File manager (edit filesystem like a buffer) |
Most Useful Shortcuts for Everyday Coding
gd → go to definition (with LSP)
gr → show references
K → show hover documentation
[d / ]d → previous / next diagnostic
<leader>rn → rename symbol
<leader>ca → code action (auto-fix, extract, etc.)
gcc → comment current line (with commentary.vim or similar)
gc{motion} → comment with motion (gcap = comment paragraph)
gf → go to file under cursor
ga → show character info
gv → re-select last visual selection
~ → toggle case of character
g~~ → toggle case of entire line
The Vim Productivity Habits
-
Never use arrow keys. Force yourself to use
hjkluntil it's muscle memory. - Learn one new motion per week. Add it to your workflow gradually.
-
Use
.(dot) constantly. Repeat the last change — it's surprisingly powerful. - Think in text objects. When you want to change something, ask "what's the text object?"
- Record a macro for anything you do twice. It takes 10 seconds to record, saves hours.
-
Use relative line numbers.
5jis faster than guessing or counting.
Exit Strategies (And Other Basics You Need)
:w → save
:q → quit (fails if unsaved changes)
:wq → save and quit
:q! → quit without saving
:wqa → save and quit all splits/tabs
ZZ → save and quit (normal mode shortcut)
ZQ → quit without saving
Vim is an investment. The first week feels slow. The second week starts clicking. By the end of the month, you are editing faster than you ever thought possible — and annoyed that other tools feel sluggish.
Start with the motions. Learn the text objects. Then everything else follows.
Level Up Your Dev Workflow
Found this useful? Explore DevPlaybook — cheat sheets, tool comparisons, and hands-on guides for modern developers.
🛒 Get the DevToolkit Starter Kit on Gumroad — 40+ browser-based dev tools, source code + deployment guide included.
Top comments (0)