0.3 — Survival Guide — Basic Modes and Exiting

0.3 — Survival Guide — Basic Modes and Exiting#

This lesson covers the absolute minimum you need to survive in Vim. By the end, you’ll be able to open a file, make changes, save, and exit—without panic.

The Most Important Thing: Modes#

Vim is a modal editor. This is the key concept that confuses beginners:

The Three Modes You Need to Know Now#

ModePurposeHow to EnterHow to Exit
NormalNavigate, delete, copy, pastePress EscEnter another mode
InsertType textPress iPress Esc
Command-lineSave, quit, searchPress :Press Esc or Enter

Rule #1: When in doubt, press Esc. This returns you to Normal mode, which is the “safe” mode.

Entering and Exiting Insert Mode#

Entering Insert Mode#

From Normal mode, press i to enter Insert mode. You’ll see -- INSERT -- at the bottom of the screen.

Now you can type text normally. Press Esc to return to Normal mode.

There are several ways to enter Insert mode:

KeyAction
iInsert before cursor
IInsert at beginning of line
aAppend after cursor
AAppend at end of line
oOpen new line below
OOpen new line above

For now, just remember i to insert and Esc to exit.

The Escape Key#

The Esc key is your friend. It:

Some people remap Caps Lock to Esc for easier access, or use Ctrl-[ which is equivalent to Esc.

Saving and Exiting#

This is what everyone wants to know: how do I exit Vim?

Basic Save and Exit Commands#

From Normal mode, type these commands (they start with :):

CommandAction
:wWrite (save) the file
:qQuit Vim
:wqWrite and quit (save and exit)
:q!Quit without saving (discard changes)
:wq!Write and quit, forcing if needed
ZZSave and quit (Normal mode shortcut)
ZQQuit without saving (Normal mode shortcut)

Step-by-Step: Edit, Save, and Exit#

  1. Open a file: vim test.txt
  2. Press i to enter Insert mode
  3. Type some text: “Hello, Vim!”
  4. Press Esc to return to Normal mode
  5. Type :wq and press Enter to save and exit

When Vim Won’t Let You Quit#

If you see an error like:

E37: No write since last change (add ! to override)

This means you have unsaved changes. You can:

Basic Navigation#

In Normal mode, use these keys to move around:

KeyMovement
hLeft
jDown
kUp
lRight

Why hjkl? On the original keyboard Bill Joy used to create vi, these keys had arrow symbols on them. More importantly, they keep your fingers on the home row.

Tip: Think of j as having a downward hook, pointing down.

Alternative: Arrow Keys#

Arrow keys also work in Vim, but experienced users avoid them because they require moving your hand from the home row. As you get comfortable, try to use hjkl instead.

Basic Editing in Normal Mode#

You don’t need to be in Insert mode to delete text:

KeyAction
xDelete character under cursor
ddDelete entire line
uUndo last change
Ctrl-rRedo (undo the undo)

Undo is Your Safety Net#

Made a mistake? Press u to undo. Vim has unlimited undo levels by default, so you can keep pressing u to go further back.

Undid too much? Press Ctrl-r to redo.

Putting It All Together: Survival Workflow#

Here’s the minimal workflow for editing a file:

1. vim filename.txt          # Open file
2. i                         # Enter Insert mode
3. [type your changes]       # Edit text
4. Esc                       # Return to Normal mode
5. :wq                       # Save and quit

If something goes wrong:

Esc                          # Return to Normal mode
u                            # Undo if needed
:q!                          # Quit without saving if you want to start over

Practice Exercise#

Create and edit a test file:

  1. Open terminal and run: vim practice.txt
  2. Press i to enter Insert mode
  3. Type: “This is my first Vim edit.”
  4. Press Esc
  5. Press o to open a new line below and enter Insert mode
  6. Type: “Learning Vim is fun!”
  7. Press Esc
  8. Type :wq and press Enter

Now reopen the file and make changes:

  1. Run: vim practice.txt
  2. Use j and k to move between lines
  3. Press dd to delete a line
  4. Press u to undo
  5. Type :q! to quit without saving

Quick Reference Card#

Print this or keep it handy:

MODES
  i       Enter Insert mode
  Esc     Return to Normal mode
  :       Enter Command-line mode

SAVE & QUIT
  :w      Save
  :q      Quit
  :wq     Save and quit
  :q!     Quit without saving
  ZZ      Save and quit (shortcut)

NAVIGATION
  h j k l Left, Down, Up, Right

BASIC EDITING
  x       Delete character
  dd      Delete line
  u       Undo
  Ctrl-r  Redo

EMERGENCY
  Esc     Return to Normal mode (always safe)
  :q!     Abandon everything and exit

Summary#

You now know enough to survive in Vim:

  1. Modes matter: Normal for commands, Insert for typing, Command-line for saving/quitting
  2. Esc is your friend: Returns you to Normal mode from anywhere
  3. :wq saves and quits: The most important command to remember
  4. u undoes mistakes: Your safety net

In the next lesson, we’ll review what we’ve learned and test your knowledge with a quiz. Then we’ll dive deeper into Vim’s modes and commands!