Survive Vim (and meet nano)
Edit files on any server, and finally learn how to get out of Vim.
- Explain modal editing, and move between normal and insert mode
- Make small edits, save and quit in Vim
- Choose nano when you just need a quick edit
Sooner or later you’ll be on a server with no graphical editor. Or Git will drop you into Vim without warning, and you’ll find that nothing you type does what you expect, and you can’t get out. Everyone has been there. You don’t need to master Vim, just to survive it.
Why typing does strange things
Vim has modes. In normal mode, which is where it starts, keys are commands rather than text. So typing a word runs a string of commands. To type, you first have to enter insert mode.
| You want to | Press |
|---|---|
| Start typing | i (insert here), a (after the cursor), o (on a new line) |
| Get back to normal mode | Esc, and when in doubt, press it again |
| Move | h j k l, or the arrow keys |
| Delete a character / line | x / dd |
| Save | :w then Enter |
| Save and quit | :wq then Enter |
| Quit without saving | :q! then Enter |
Try it
Up to 15 XPEscape from Vim
This is a small but real modal editor. Click the black editor first, then use your keyboard, or the buttons below it. Keep an eye on the bottom bar: it always tells you which mode you’re in.
Challenge 1 of 4: You’ve landed in Vim by accident. Get out without changing anything.
Click the editor to type, or use these keys.
Or just use nano
If Vim isn’t for you, nano is on most systems and works the way you’d expect: type to edit, and the commands are listed at the bottom, where ^ means Ctrl. Ctrl-O saves and Ctrl-X exits. To stop Git opening Vim, set your editor: export EDITOR=nano. It’s still worth knowing the Vim escape plan, because some minimal servers have nothing else.
Key takeaways
Vim has modes: normal for commands, and insert for typing.
Esc always gets you back to normal mode.
:wq saves and quits, and :q! quits without saving.
nano is fine, and you can set it as your EDITOR.
Lesson quiz
5 questions · pass with 4 correct · up to 50 XP
Passing this quiz completes the lesson and keeps your streak going. Questions you miss come back in review sessions later.
Questions about this lesson
Stuck? Ask. Figured something out? Share it. Explaining is one of the best ways to learn.
Loading posts…