Vim modes explained: Normal, Insert, Visual and Command

DJC > Tutorials

| Vim |

Vim is a modal editor: its behavior depends on the "mode" you're in. Understanding and mastering the four basic modes — Normal, Insert, Visual and Command — is the key to editing text quickly and efficiently.

Quick summary

  • Normal: the default mode for navigating and editing with commands (without inserting text directly).
  • Insert: for typing text literally (like in a traditional editor).
  • Visual: for selecting text (characters, words or lines) and then operating on the selection.
  • Command (command-line): to run complex commands, save, quit, replace, search, etc.

Normal mode

What it is

  • It's the mode for navigating, deleting, copying, pasting and running most Vim commands.

How to enter

  • When you open Vim you're already in Normal. If you come from Insert, press Esc or Ctrl-[ to return to Normal.

Useful commands (Normal mode)

  • h, j, k, l — move the cursor (left, down, up, right).
  • w, b, e — move by words (next, previous, end of word).
  • 0 (zero) and $ — go to the beginning and end of the line.
  • dd — delete the line (and copy it into the register).
  • yy — yank (copy) the line.
  • p — paste after the cursor.
  • u — undo.
  • Ctrl-r — redo.
  • /text — search forward; n for next, N for previous.

Examples

  • 5j — move down 5 lines.
  • 3dw — delete 3 words from the cursor.

Tips

  • Combine numbers with commands: 10j moves down 10 lines, 2dd deletes two lines.

Insert mode

What it is

  • The mode for inserting text literally.

How to enter

  • Press i (insert before the cursor), I (at the start of the line), a (insert after the cursor), A (at the end of the line), o (open a new line below), O (open a new line above).

How to exit Insert

  • Esc or Ctrl-[ to return to Normal mode.

Quick tips

  • Use Ctrl-o from Insert to run a single Normal command and return to Insert.

Visual mode

What it is

  • Used to select text and then apply commands (delete, copy, change, etc.). There are three sub-modes: characterwise visual, linewise visual and blockwise visual.

How to enter

  • v — characterwise visual.
  • V — linewise visual.
  • Ctrl-v — blockwise visual (rectangular selection).

Useful commands inside Visual

  • y — yank (copy selection).
  • d — delete the selection.
  • > and < — indent selection right/left.
  • :s/pattern/repl/ — you can run substitutions on the selection (press : after selecting and you'll see :'<,'> in the command line).

Examples

  • Select a word: place the cursor on the word and press v + iw (inner word) or use viw directly from Normal.
  • Select 3 lines: V2j and then y to copy.

Command mode (command-line)

What it is

  • Also called Ex mode or command-line mode. It's used to save, quit, search and replace with more advanced syntax.

How to enter

  • From Normal press : to open the command-line at the bottom.

Common commands

  • :w — write (save).
  • :q — quit.
  • :wq or :x — save and quit.
  • :q! — quit without saving.
  • :e file — open/edit another file.
  • :%s/old/new/g — replace throughout the file (global).
  • :set number — show line numbers; :set nonumber to hide them.

Search and replace

  • :/pattern starts a search; often /pattern from Normal is more convenient.
  • Replacement with confirmation: :%s/old/new/gc (asks before each replacement).

Typical workflow and shortcuts to be more efficient

  1. Navigate in Normal (use w, b, f, t, } and { to move quickly).
  2. Enter Insert (i or a) to type or edit text.
  3. Return to Normal (Esc) and use Visual to select if you need to move/change blocks.
  4. Use the command-line (:) to save, search or run complex substitutions.

Speed-up shortcuts

  • . — repeat the last command (very powerful).
  • ciw — change (delete + enter Insert) the inner word.
  • ci{ or ci( — change the inner content of a block between braces/parentheses.

Practical exercises (5–10 minutes each)

  1. Open a text file with several lines. In Normal, use :set number and practice moving the cursor with 10j, 5k, 0 and $.
  2. Insert a new line below the current one with o, type text, and return to Normal with Esc. Repeat 5 times and then use dd to delete three of those lines.
  3. Copy 2 lines with yy or 2yy and paste them after with p.
  4. Select a word with viw and replace it by typing c + new text + Esc.
  5. Do a safe global substitution: :%s/foo/bar/gc and answer the confirmations.

Common mistakes and how to avoid them

  • Staying in Insert and pressing key combinations thinking they are shortcuts: remember to get back to Normal with Esc.
  • Forgetting that dd and yy store content in registers; if you paste something unexpected, you might have yanked something else.
  • Using :wq when you only wanted to quit without saving: use :q! to discard changes.

Quick resources to learn more

  • Run vimtutor in the terminal for an interactive tutorial (highly recommended).
  • Look for "vim tips" guides and cheatsheets (for movements, operators, text objects).

If you want, I can:

  • Add GIFs or images that show the keys and effects.
  • Include advanced practical examples (macros, registers, useful plugins).
  • Create an exercises page with solutions or adapt this into a short interactive tutorial.

Tell me which option you prefer and I'll add it.

DJC > Tutorials