DEV Community

楊東霖
楊東霖

Posted on • Originally published at devplaybook.cc

Vim/Neovim Productivity Tips Every Developer Should Know

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]
Enter fullscreen mode Exit fullscreen mode
  • Operator: what to do (d delete, c change, y yank, v select)
  • Motion: what to act on (w word, $ 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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

Jump List

Ctrl-o   → jump back to previous location
Ctrl-i   → jump forward
:jumps   → show jump list
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

Registers: Copy/Paste on Steroids

Vim has 26 named registers (az) 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
Enter fullscreen mode Exit fullscreen mode
:reg     → view all registers
"+yy     → yank line to system clipboard
"+p      → paste from system clipboard
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

Or use :normal for a visual selection:

:'<,'>normal A;    → append ; to every selected line
Enter fullscreen mode Exit fullscreen mode

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/ddelete all console.log lines
:g/TODO/normal I# → add # to start of every TODO line
:g/^$/ddelete all blank lines
:v/import/ddelete all lines that DON'T contain "import"
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

Capital marks (A-Z) work across files — a global bookmark that persists across sessions.


Windows, Tabs, and Buffers

# Buffers (open files)
:lslist open buffers
:b3       → switch to buffer 3
:b name   → switch to buffer by name
:bn / :bp → next / previous buffer
:bdclose buffer

# Splits
:split / :sp     → horizontal split
:vsplit / :vsvertical 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
:tabnewnew tab
gt / gT          → next / previous tab
:tabcloseclose tab
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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

gdgo 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
Enter fullscreen mode Exit fullscreen mode

The Vim Productivity Habits

  1. Never use arrow keys. Force yourself to use hjkl until it's muscle memory.
  2. Learn one new motion per week. Add it to your workflow gradually.
  3. Use . (dot) constantly. Repeat the last change — it's surprisingly powerful.
  4. Think in text objects. When you want to change something, ask "what's the text object?"
  5. Record a macro for anything you do twice. It takes 10 seconds to record, saves hours.
  6. Use relative line numbers. 5j is faster than guessing or counting.

Exit Strategies (And Other Basics You Need)

:w      → save
:qquit (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
Enter fullscreen mode Exit fullscreen mode

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)