Vim has a special place in computing: the editor people are scared of not because it is hard, but because nobody told them the fifteen commands that matter. I was one of those people. My first encounter ended with me mashing keys and then rebooting a server to escape, which is embarrassing to admit and apparently a shared experience for half the internet.
Here is the secret: you do not need to learn Vim. You need to survive it — edit a config file on a server, save, get out. This guide is exactly that, plus a few extras that will make you unexpectedly fast.
The one idea that explains everything
Vim has modes, and 90% of beginner pain comes from not knowing which one you are in:
- Normal mode — where you start. Keys are commands, not text
-
Insert mode — where typing actually types. Enter it with
i, leave it withEsc -
Command mode — the
:line at the bottom, for saving/quitting
When in doubt, press Esc a couple of times. You are now in Normal mode and nothing you type will accidentally edit the file. Esc is your home base.
The survival set
Open a file: vim /etc/nginx/nginx.conf. Then:
| You want to... | Do this |
|---|---|
| Start typing at the cursor | i |
| Stop typing | Esc |
| Save |
:w then Enter |
| Save and quit |
:wq then Enter |
| Quit without saving |
:q! then Enter |
| Undo (the panic button) |
u in Normal mode |
| Redo | Ctrl+r |
| Move around | Arrow keys work fine, ignore the purists |
That is genuinely enough to edit server configs for the rest of your life. :q! is the answer to the famous "how do I exit Vim" question, and u is the answer to "I pressed something and now the file looks wrong".
The commands that make you faster than nano
Once survival is boring, these are the ones that feel like upgrades:
Delete a whole line: dd. No selecting, no mouse. 5dd deletes five lines. This is the command that converts people.
Copy and paste a line: yy to yank (copy), p to paste below. 5yy then p duplicates a block — perfect for duplicating a config section and editing the copy.
Jump to a line number: :42 then Enter goes to line 42. When an error says "syntax error on line 87", you want :87, not twenty seconds of scrolling.
Search: /nginx then Enter, n for the next match, N for the previous. This is how you find server_name in a 400-line file instantly.
Go to top / bottom: gg for the first line, G for the last. Config files end up at the bottom a lot; G gets you there immediately.
Delete a word: dw. Change a word: cw — deletes the word and drops you into Insert mode, which is exactly what you want when renaming a variable.
A tiny real-world session
Say nginx failed and nginx -t complains about line 42 of the config:
vim /etc/nginx/nginx.conf
:42 " jump to the broken line
i " fix the typo
Esc
:w " save
:q " quit
Four commands, error fixed, no mouse, no fear. That is the entire game.
Two things that confuse everyone
"Vim is not typing, it is just beeping." You are in Normal mode. Press i to insert text. This is the #1 beginner moment.
"I edited a file and it says read-only." The file needs root. Quit with :q! and reopen with sudo vim /etc/.... (There is also a trick to save anyway — :w !sudo tee % — but reopening with sudo is easier to remember.)
And the version question: on most servers vim is what you have; on minimal systems vi works the same for everything in this guide. nano is a fine editor too — but every server in the world has vi, so these fifteen commands are the ones that never leave you stranded.
Learn i, Esc, :wq, :q!, u today. Add dd, yy, p, / this week. By next week you will be the person other people ask how to exit Vim — and that is when you know you have made it.
Top comments (0)