I’ve noticed that people older than me have always known just a few more vi commands than I do.
I’m in my 40s, so clearly I know about 4:
Writes and quits (I consider these variants of the same thing):
:w
:q
:q!
:wq
ZZ
See the line numbers:
:set number
Delete everything from top to bottom (must be at top, easily remembered by mumbling duck, duck, duck, GOOSE):
:dddG
Search for a string:
/
And that’s probably it. I think I used to know how to cut a line and paste a line, but I’d have to look it up to be 100% correct on the syntax.
Anyone in their 50s or 60s care to add to this dazzlingly long list of inadequacy? Not looking for a cheat sheet or the man page :-p
Very useful for renaming a variable:
*
to search “word” under cursor. Try this with hlsearch on::set hlsearch
. Thencw
to change a match. Alternaten
and.
to quickly rename more occurrences of the word. Do a:noh
to get rid of the highlighting. Maybe try:set noinc
, some people prefer the traditional “non-incremental” search.Do all this in normal mode. Vim experts leave insert mode as soon as possible. Almost forgot: Pressing
C-c
takes you back to normal mode without leaving home row.Most important advice: Never touch arrow keys. Keep your fingers on the home row. Learn
hjkl
movement (focus onj
andk
, they are more important). Then get faster by usingb
,w
,f
,o
,O
,A
,I
,C-d
and all the rest. Learn aboutJ
, it’s cool. You won’t get far withoutu
andC-r
though.Critically important advice for fellow Europeans: If you care about vim, consider learning the US keyboard layout. Default bindings are not convenient in other layouts like qwertz (where is forward slash on qwertz? Hello?), and learning US layout might be easier than learning to customize vim. On a typical modern Linux system, there are US layout variants that still allow typing Umlauts, like EurKey or “DE-US”, where you type
ä
by pressing RightAlt+a, for example.