Visual Mode: Precision Selection

[!NOTE] What is Visual Mode? In standard editors, you click and drag to select text. In Vim, you enter Visual Mode to define a selection, then apply an Operator to that selection. It follows the grammar: Select → Operate.

1. The Three Visual Modes

Vim offers three distinct ways to select text, each optimized for different structures.

1. Character-wise Visual Mode (v)

Standard selection, similar to mouse dragging. Selects characters from point A to point B, wrapping around lines.

2. Line-wise Visual Mode (V)

Selects entire lines. Perfect for moving paragraphs or deleting blocks of code.

3. Block-wise Visual Mode (Ctrl-v)

The superpower. Selects a rectangular block (column). Essential for editing tables, aligning comments, or refactoring variable lists.

Interactive: Visual Mode Simulator

Click a mode to see how it selects text starting from the cursor position (█).

2. Operating on Selection

Once you have selected text, you hit an operator key to perform an action.

Key Action
d Delete selection (and cut to register).
y Yank (copy) selection.
c Change selection (delete and enter Insert mode).
~ Toggle Case (upper/lower).
> Indent selection right.
< Outdent selection left.
= Auto-format/indent selection.
u / U Make selection lowercase / UPPERCASE.

[!TIP] Quick Re-selection Accidentally lost your selection? Press gv to re-select the last visual area. This is a life-saver.

3. Visual Block Power: Multi-Line Edits

The true power of Visual Block mode (Ctrl-v) is the ability to edit multiple lines simultaneously.

1. Inserting on Multiple Lines

Scenario: You want to add // to comment out 5 lines of code.

  1. Move to the start of the first line.
  2. Press Ctrl-v to enter Block mode.
  3. Move down (j or 5j) to select the column.
  4. Press Shift-I (capital I) to Insert at the start of the block.
  5. Type //.
  6. Press <Esc>.
  7. Wait a moment… Vim automatically applies the text to all selected lines.

2. Appending to Lines

Scenario: Add a comma , to the end of a list of JSON properties.

  1. Enter Block mode Ctrl-v.
  2. Select the column (even if lines are different lengths, select the block covering the visual end).
  3. Press $ to extend the block to the end of each line.
  4. Press Shift-A (capital A) to Append.
  5. Type ,.
  6. Press <Esc>.

4. Navigation within Selection

When you have a large selection, your cursor is at one end. What if you need to adjust the start of the selection?

  • o: Go to Other end of the selection. Pressing it toggles your cursor between the start and end point.
  • O: (In Block mode) Go to the Other corner (horizontally).

[!CAUTION] Mouse Selection If you enabled mouse support in Vim (set mouse=a), dragging with the mouse enters Visual Mode automatically. While convenient, rely on keyboard motions (vip, V}, vt;) for speed.

5. Practice Exercise

Open Vim and type this list:

item 1
item 2
item 3
item 4

Goal: Change it to a markdown task list ` - [ ] item 1`.

  1. Move to item 1.
  2. Ctrl-v to select the column i down to item 4.
  3. Shift-I (Insert before).
  4. Type ` - [ ] `.
  5. <Esc>.

Witness the magic.