Modes

Everything in Vim makes more sense once modes click, so this chapter is the most important one in the book. Take it slow.

The four modes you’ll actually use

Normal mode is where you start, and where you’ll spend most of your time. In Normal mode, keys are commands. j moves down. x deletes a character. dd deletes a line. Nothing you type here inserts text; it navigates and edits.

Insert mode is where typing works the way you expect. Press i from Normal mode to enter it, and now the letters you press appear in the file. Press Esc to leave Insert mode and go back to Normal mode.

Visual mode lets you select text, the way click-and-drag does in other editors, except you use motions instead of a mouse. Press v from Normal mode to start selecting, move around to grow the selection, then run a command like d to delete it. Covered in more depth in chapter 5 .

Command-line mode is for one-off instructions like saving, quitting, or search-and-replace. Press : from Normal mode and you’ll see a colon prompt at the bottom of the screen. Type a command, hit Enter, and you’re back in Normal mode.

The one rule that matters most

Esc always takes you back to Normal mode, from anywhere. If you’re not sure what mode you’re in, press Esc and you’ll be in Normal mode, guaranteed. This is the single most useful fact in this chapter. When in doubt, hit Esc.

Getting in and out of Insert mode

There’s more than one way into Insert mode, and the difference is where your cursor ends up:

  • i inserts before the cursor
  • a inserts after the cursor
  • I inserts at the start of the line
  • A inserts at the end of the line
  • o opens a new line below and inserts there
  • O opens a new line above and inserts there

You don’t need to memorize all six today. Start with i, a, and o. The other three will make sense once you’ve used Vim for a few days and gotten annoyed at having to move the cursor manually.

Checking which mode you’re in

Most terminal Vim setups show the mode in the bottom-left corner: -- INSERT --, -- VISUAL --, and so on. Normal mode usually shows nothing there, which is itself a clue: no label means Normal mode.

Try it

Open a scratch file (vim scratch.txt) and work through these in order:

  1. You’re in Normal mode when the file opens. Press i and type a sentence. Notice the mode indicator changes.
  2. Press Esc. Confirm the indicator disappears, meaning you’re back in Normal mode.
  3. Move to the end of the line (you’ll learn the real way to do this in the next chapter, but for now just hold the right arrow key). Press A and type a few more words. Press Esc.
  4. Press o to open a new line below, type something, press Esc.
  5. Press : and type q! then Enter to quit without saving. You now know how to get in, get out, and leave without your experiments haunting you.

← Before You Start