DaleSchool

Visual Mode

Beginner15min

Learning Objectives

  • Use the three visual modes: v, V, and Ctrl+v
  • Apply operators to selections made in Visual mode
  • Edit multiple lines at once with block selection

Working Code

Imagine this code is open in Vim:

name = "Alice"
age = 25
city = "Seoul"
email = "alice@example.com"

Press V on the first line and the whole line is highlighted. Press j twice — three lines are now selected. Press d and all three lines disappear at once.

That's Visual mode. It's a select-first, then-act style of editing.

Try It Yourself

Try all three visual modes on this code:

const items = ["apple", "banana", "cherry", "date"];

1. Character-wise Visual mode (v):

  • Place the cursor on "apple", press v, then e to extend selection to the end of the word.
  • Press y to yank, then p elsewhere to paste.

2. Line-wise Visual mode (V):

  • On the "banana" line, press V, then j to extend through "cherry".
  • Press > to indent the selection.

3. Block-wise Visual mode (Ctrl+v):

  • Place the cursor on " of each line, press Ctrl+v.
  • Press 3j to select four lines, then press I (uppercase) and type // .
  • Press Esc// is inserted on all four lines.

"Why?"

The three visual modes

ModeKeySelection unitMain use
Character-wisevPer characterSelecting words or phrases
Line-wiseVPer lineDeleting, moving, or indenting lines
Block-wiseCtrl+vRectangleEditing multiple lines / column select

Commands you can apply after selecting

Apply any of these after making a selection:

KeyAction
dDelete the selection
yYank the selection
cDelete the selection and enter Insert mode
>Indent
<Unindent
~Toggle case
UUppercase
uLowercase
JJoin selected lines into one

The magic of block-wise visual

Block-wise Visual mode (Ctrl+v) is one of Vim's most powerful features. It lets you edit multiple lines simultaneously.

Prepending text to multiple lines:

1. Start block selection with Ctrl+v
2. Extend with j or k to the last line
3. Press I (uppercase) to enter Insert mode
4. Type the text
5. Esc → same text is prepended to every selected line

Appending text to multiple lines:

1. Start block selection with Ctrl+v
2. Extend with j to the last line
3. $ extends selection to the end of each line
4. Press A (uppercase) to append
5. Type the text, then Esc

Handy tips

  • gv: Re-select the last visual selection. Useful for repeated indenting.
  • o: In Visual mode, move the cursor to the other end of the selection.
  • Esc: Cancel Visual mode and return to Normal mode.

Operator + motion vs. Visual mode

The d2w (delete 2 words) from the previous lesson works without Visual mode. So when do you use Visual mode?

  • When you want to see the exact range before acting
  • When you need block (column) editing
  • When the range is too complex to express as a motion

As you grow comfortable, you'll reach for operator+motion for simple edits and Visual mode for complex ones.

Deep Dive

Using text objects in Visual mode

Text objects work in Visual mode too:

vi"     → select content inside quotes
vi{     → select content inside braces
vip     → select the current paragraph

Once selected, apply d, y, c, etc. The end result matches typing di" directly, but you get to confirm the selection visually.

Add/remove comments with block editing

Paste the code below into Vim and comment it out using block Visual mode:

name = "Alice"
age = 25
city = "Seoul"
email = "alice@example.com"
  1. Place the cursor at the start of the first line.
  2. Enter block Visual mode with Ctrl+v.
  3. Select four lines with 3j.
  4. Press I (uppercase), type # , and press Esc.
  5. Check the result. Are all four lines commented?

To remove the comments: Ctrl+v3jl (select 2 columns) → d

question: "Which visual mode lets you edit multiple lines simultaneously?" options:

question: "Which key converts a Visual-mode selection to uppercase?" options:

question: "What does gv do?" options: