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
gvto 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.
- Move to the start of the first line.
- Press
Ctrl-vto enter Block mode. - Move down (
jor5j) to select the column. - Press
Shift-I(capitalI) to Insert at the start of the block. - Type
//. - Press
<Esc>. - 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.
- Enter Block mode
Ctrl-v. - Select the column (even if lines are different lengths, select the block covering the visual end).
- Press
$to extend the block to the end of each line. - Press
Shift-A(capitalA) to Append. - Type
,. - 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`.
- Move to
item 1. Ctrl-vto select the columnidown toitem 4.Shift-I(Insert before).- Type ` - [ ] `.
<Esc>.
Witness the magic.