Master Vim: Essential Command Mode, Navigation, and Repetitive Editing Techniques
This article explains how to harness Vim’s core principles of command‑mode habit, efficient cursor movement with HJKL, repeatable editing commands, visual‑block tricks, and practical examples, enabling developers to edit faster and break the mouse‑driven workflow.
The author has been using Vim for over a year across languages such as PHP and C, and argues that Vim’s two essential ideas are combination and repetition , not merely plugins.
Command Mode Should Be the Default
In most editors you save with Ctrl+S, but in Vim you must be in command mode and type
: w. This often requires pressing Esc then :w, a three‑key sequence. Beginners dislike this, yet mastering the habit of switching to command mode whenever you are not inserting text is the first crucial reflex for any Vimer.
HJKL Lets Your Right Hand Rest
HJKL are the cursor‑movement keys in Vim. Although you could use the arrow keys, frequent use of command mode makes HJKL a reflex that reduces right‑hand travel distance, freeing the hand for other tasks.
Make Your Operations Repeatable
Example: Transform the line one two three four five six into "one","two","four","five","six". Position the cursor at the line start with ^, then use f to find the first space,
c ,to replace it, and repeat with ; and .. Finally add surrounding quotes with I and A. This demonstrates the repeatable nature of f, c, ; and . commands.
one two three four five six "one","two","four","five","six"Efficient Movement
Enable relative line numbers with set relativenumber to see offsets from the cursor. Use numeric prefixes with +j and +k for multi‑line jumps, or commands like 138gg to go to a specific line. Other useful motions include: w, e, b – word‑wise navigation (repeatable with counts). I, A – move to line start or end and enter insert mode. H, M, L – jump to top, middle, or bottom of the visible window. Ctrl+D, Ctrl+U – page down/up. ^, $, 0 – move to line start/end (note the shift requirement for ^ and $). % – jump to the matching bracket. gj, gk – move down/up visual lines when lines wrap. f, F – find a character forward or backward. ; – repeat the last f / F search. . – repeat the last change command.
Efficient Editing
Replace single characters with r, change a word with cw, change a whole word with caw, delete to end of line with c$, and edit inside delimiters with ci", ci(, ci[, or cit for XML tags. Yank (copy) with y variants such as yi" (yank inside quotes) and ya" (yank around quotes). Use o and O to insert blank lines, and u / Ctrl+r for undo/redo.
Visual Mode: A Mouse‑Flow After‑Effect with Hidden Benefits
Visual mode ( v, V, Ctrl+v) mimics mouse selection. While vwd (visual‑word‑delete) is a mouse‑style habit, block visual mode ( Ctrl+v) lets you select columns. For example, turning a vertical list:
one
two
three
fourinto a single quoted, comma‑separated line: "one, two, three, four" can be done with a sequence like Ctrl+v 3j $ A , Esc V 3j J. Knowing the relative line numbers helps determine the 3j count.
Conclusion
Vim may not surpass full IDEs in raw features, but its editing speed can exceed mouse‑driven workflows. Mastering Vim is a continual process of learning new tricks, reshaping habits, and developing a personal editing style.
MaGe Linux Operations
Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
