Visual Mode

Most of the time, operators and motions (dw, 3dd, y$) get you where you need to go without ever selecting anything by hand. But sometimes you want to see exactly what you’re about to act on before you commit to it. That’s what Visual mode is for.

Three flavors of selection

v starts character-wise Visual mode. Move around with any motion you already know (w, $, j, whatever), and the selection grows from where you started to wherever your cursor is now.

V (capital) starts line-wise Visual mode. Instead of selecting characters, it selects whole lines, which is what you want most of the time when working with lines of code or text rather than fragments of them.

Ctrl-v starts block Visual mode, also called Visual Block. This selects a rectangular block of text, useful for things like adding the same prefix to the start of several lines at once. It’s less common for prose, more common when editing code or tables.

Once you’ve selected something

Selection alone doesn’t do anything. It’s the setup for a command. With text selected in any Visual mode:

  • d deletes the selection
  • y yanks (copies) the selection
  • c deletes the selection and drops you into Insert mode to type a replacement
  • > and < indent or unindent the selected lines

The pattern should feel familiar: select first, then run a command, similar to how dw combines an operator with a motion, except here you’re choosing the target visually instead of naming a motion.

Escaping Visual mode

Esc exits Visual mode without doing anything, exactly like it exits Insert mode. If you start a selection and change your mind, Esc gets you back to Normal mode with nothing altered.

Try it

Open a scratch file with a few lines of text and practice:

  1. Press v, move a few characters to the right, then press d to delete the selection.
  2. Press V, move down two lines to select three lines total, then press d to delete them all at once.
  3. Press V again, select a couple of lines, and press y to yank them, then move elsewhere and p to paste.
  4. Type several lines that start with a shared word or character, then use Ctrl-v, move down to cover a few lines, and try deleting the first column with d.
  5. Start a v selection, then press Esc before running any command. Confirm nothing changed.

← Search and Replace