Best Practices: Idioms, Habits, and Knowing When to Step Out
This chapter distils the muscle-memory patterns worth building, the anti-patterns worth unlearning, and the moments when the right move is to close Vim and open something else.
Think in Verbs
The foundational shift is to stop thinking "I need to change this text" and start thinking in operators and motions:
- I want to change the word I'm on:
ciw - I want to delete the string inside these quotes:
di" - I want to yank the function body:
yi{ - I want to indent the paragraph:
>ip
When you catch yourself arrowing through text, stop. Name what you want in operator-plus-motion form. Type that. It will be shorter.
Use the Smallest Tool
Vim offers several tools for "do the same thing many times". Reach for them in this order:
- The dot command (
.) for a single repetition - A motion with
.(nthen.,fthen.) for scattered repetitions :substitutefor mechanical replacements across a file- A macro when the change varies slightly per occurrence
- A function or plugin when the change is complex or you'll do it across projects
Starting at the top keeps your toolkit simple. If you're writing a 200-line plugin to do what :%s/old/new/g does, you skipped too many steps.
Learn One Thing a Week
You can use Vim effectively with twenty commands. You can use it well with a hundred. There is always another.
Pick one piece per week: a new text object, a new motion, a new register trick. Force yourself to use it for the week. At the end, keep it if it stuck. Don't try to learn five things at once. You'll learn none.
Some candidates if you're looking:
ci",ci(,ci{text object variants you haven't tried- The
zfold commands - The
"0register gito resume insert mode at the last spotgeandgEfor "back to end of previous word"*and#for word under cursorq:to browse command history
The Dot Command is Your Default
If you change to DONE and want every other TODO to become DONE, don't write a macro. Do this:
/TODO<Enter> search
cwDONE<Esc> change word
n next match
. repeat
n next
. repeat
Four keys per occurrence. Zero planning. If it's too repetitive to bear, you probably wanted :%s/TODO/DONE/g in the first place.
Favour Linewise Edits When You Can
Linewise operators (dd, yy, >>, ==) are often faster than charwise equivalents. The row is usually the unit you care about.
10dd delete 10 lines
5== auto-indent 5 lines
>ip indent the current paragraph (linewise)
You almost never need to "delete three characters and then the next four". You usually want to delete to a word boundary, the end of a line, or the end of a paragraph. Pick the unit, apply an operator, move on.
Anti-Patterns
Holding hjkl
If your cursor is more than five lines away, don't hold j. Use:
10jto jump a count/pattern<Enter>to search}or{to jump paragraphs<C-d>or<C-f>to scroll pagesGorggto jump to start or end:42<Enter>to jump to line 42
Holding a motion key is the Vim equivalent of double-clicking to move the cursor.
Using arrow keys
Arrows work. They also keep your hand off the home row. Every time you reach for an arrow, you break the flow that hjkl plus operators keeps tight. Rebind arrows to nothing if you need a kick:
nnoremap <Up> <Nop>
nnoremap <Down> <Nop>
nnoremap <Left> <Nop>
nnoremap <Right> <Nop>
Harsh. Effective.
Escaping with Escape
Some setups make <Esc> feel sluggish. Map jk or kj to escape in insert mode:
inoremap jk <Esc>
Your right hand never leaves home row. <Esc> becomes a last resort.
Over-configuring early
New Vim users add fifty plugins, three color schemes, and a 400-line .vimrc in a weekend. Then they wonder why their setup feels complicated.
A reasonable order:
- Use Vim with near-default settings for two weeks
- Add things only when you feel the pain they solve
- Read someone else's
.vimrcfor ideas, not to copy wholesale
Your .vimrc should grow in response to real friction, not in advance of it.
Bloated plugin lists
Every plugin you add is a potential source of start-up delay, keybinding conflict, and mystery behaviour. Review your Plug list every few months. Delete anything you haven't invoked on purpose.
Memorising commands you never use
:help is excellent. You do not have to memorise everything. If you use :retab once a year, just look it up when you need it. Use your memory on what you use daily.
Good Habits
Save often, idly
:w is one motion. Map it to <leader>w and flick it every time you stop typing. Auto-save plugins exist too, but the manual habit is better. A :w is also the best time to reflect on what you just changed.
Use fewer buffers than you think
One open buffer per file you're actively touching. Close the rest with :bd or :bufdo bd. Vim's buffer list gets cluttered fast; keeping it short makes :b partial feel instant.
Record macros when the dot command is not enough
A macro is just "a sequence you'd otherwise type ten times". Don't pre-plan. Start recording at the moment you notice the second repetition coming. If it works, 100@a. If it doesn't, undo and rethink.
Learn through real work
vimtutor is excellent for mechanics. Projects teach you habits. Use Vim for one real task a day until you stop needing to ask "how do I do X in Vim".
Read :help
When stuck, :help is almost always the answer. Search, follow tags, come back out. After a few months, you'll recognise which help topic has what you need:
:help motion.txt
:help text-objects
:help registers
:help :substitute
:help autocmd-events
:help pattern-overview Vim's regex syntax
:help usr_toc user manual table of contents
Keep a list of "weird things I learned"
Every few weeks, you'll learn something surprising: Ctrl-A increments numbers, gx opens URLs, gq reformats paragraphs. Jot them down. Come back and use them.
Useful Idioms Worth Stealing
Copy these into your toolkit:
ggVG select the entire file
ggVGd delete the entire file's contents
=G auto-format from cursor to end of file
gg=G auto-format the whole file
:%y+ yank the whole file to the system clipboard
:%s/\s\+$//e strip trailing whitespace (map to <leader>s)
cs"' change surrounding double to single (vim-surround)
gUiw uppercase the word under the cursor
g~iw toggle case of the word
yap yank a paragraph including trailing blank line
viw select a word
daw delete a word and its surrounding space
None of these are tricks; they are idioms you'll see in any fluent Vim user's hands.
When to Step Out of Vim
Vim is not the right tool for everything. Leave cheerfully when the task asks you to.
- Heavy debugging with breakpoints: your IDE probably does this better. Many have a Vim mode
- Refactoring across many files with type awareness: LSP rename, or a refactoring-aware IDE
- Git reviews with visual diff: a dedicated UI is smoother than fugitive for some flows
- Writing prose with track-changes and comments: a word processor
Good Vim users are not religious about Vim. They know what it is (a text editor, a very good one) and what it isn't (a full IDE, a writing suite).
Becoming Fluent Takes a Year
Vim has a long tail. You'll feel productive in a week, competent in a month, fluent in a year. That timeline is normal. Don't skip steps:
- Week 1:
hjkl, insert mode, save, quit,:help - Month 1: operators, motions, text objects, basic
.vimrc - Month 3: registers, macros, buffers,
:substitute,:global - Year 1: advanced techniques, plugins, maybe some vimscript
Don't rush. Each layer makes the next one easier. People who try to learn it all in a weekend end up hating Vim. People who let it seep in end up using it for the rest of their career.
Where to Go From Here
- Work through
vimtutoronce more, cold - Read
:help usr_tocfront to back over a few weekends - Read Practical Vim by Drew Neil. It is the best book on Vim
- Watch a fluent user work and steal one habit
- Read other people's
.vimrcfiles on GitHub for ideas - Try Neovim if you haven't; the config ergonomics are worth the swap
- Learn one motion or text object a week until there's nothing left to learn
There is no finish line with Vim. That is the feature.