vim Introduction

"How do I exit vim?" is the most famous programming joke. Let's make sure you're never stuck.

vim is powerful, fast, and everywhere. But it's weird at first because it uses modal editing.

Why vim Seems Confusing

You open vim, start typing... nothing appears. Or random things happen. You press Escape. Things get worse. You close the terminal in frustration.

Sound familiar? That's because vim works differently.

Most editors have one mode: you type, text appears.

vim has modes:

ModePurposeHow to Enter
NormalNavigate, delete, copyEsc
InsertType texti, a, o
VisualSelect textv
CommandSave, quit, search:

Why Modes?

In Normal mode, every key is a command. d deletes, w moves forward a word, y copies. No Ctrl+This or Alt+That - just letters. Fast once you learn it.

Your First vim Session

Terminal
$vim test.txt
(opens vim)

You're now in Normal mode. Notice the cursor.

To Type Text

  1. Press i (enter Insert mode)
  2. Type your text
  3. Press Esc (return to Normal mode)
Terminal
$i
-- INSERT -- (appears at bottom)
$Hello, vim!
(text appears)
$Esc
(back to normal mode)

To Save and Quit

  1. Make sure you're in Normal mode (press Esc)
  2. Type :wq and press Enter
Terminal
$Esc
(ensure Normal mode)
$:wq
(write and quit)
$Enter
(file saved, vim exits)

The Emergency Exits

Quit without saving:

Esc :q! Enter

Save and quit:

Esc :wq Enter

Just save:

Esc :w Enter

When in Doubt, Press Escape

If vim is doing something weird, press Esc a few times. You'll return to Normal mode where you can figure out what to do next.

Why Learn vim?

  • It's everywhere: Every Unix system has vi/vim
  • Fast: Once proficient, you edit faster than any GUI
  • Keyboard-only: No mouse needed (servers don't have mice)
  • Remote editing: Perfect for SSH sessions
  • IDE integration: vim keybindings in VS Code, JetBrains, etc.

vim vs vi

vi is the original (1976). vim is "Vi IMproved" (1991) with many more features.

Terminal
$vi file.txt
(usually runs vim in compatibility mode)
$vim file.txt
(full vim features)

On most systems, vi is actually vim.

The Learning Curve

Productivity
    ^
    |           vim masters
    |              /
    |             /
    |            /
    |           /
    |    ___---
    |  /
    | /  nano
    |/
    +-----------------> Time

vim has a steep initial curve but much higher ceiling.

vimtutor - Built-in Tutorial

The best way to learn vim is the built-in tutorial:

Terminal
$vimtutor
(opens interactive tutorial)

It takes about 30 minutes and teaches you the essentials through practice. Run it a few times over a week - the repetition helps.

Learning Plan

  1. Complete vimtutor once today
  2. Force yourself to use vim for small edits
  3. Run vimtutor again in a few days
  4. After a week, vim will feel natural
Knowledge Check

What mode are you in when you first open vim?

Quick Reference

ActionKeys
Enter Insert modei
Return to Normal modeEsc
Save:w
Quit:q
Save and quit:wq
Quit without saving:q!

Key Takeaways

  • vim uses modes: Normal, Insert, Visual, Command
  • Press i to type, Esc to stop typing
  • :wq saves and quits
  • :q! quits without saving
  • Press Esc when confused
  • Learning curve is worth it

Next: essential vim commands you'll use daily.