Vim’s visual mode isn’t just for selecting text; it’s a powerful, often-underestimated, way to manipulate blocks of text in ways that go far beyond simple copy-pasting.

Let’s see it in action. Imagine you have this configuration file:

database_host: localhost
database_port: 5432
database_user: admin
database_password: secret_password

You want to change all the database_ prefixes to app_.

First, place your cursor on the d in database_host. Now, press v to enter visual mode. You’ll see the cursor turn into a block and the characters you’re highlighting will change color.

Move your cursor to the right until you’ve highlighted database_.

Now, press c (for change). Vim deletes the highlighted text and drops you into insert mode. Type app_ and press Esc.

app_host: localhost
database_port: 5432
database_user: admin
database_password: secret_password

That’s just the start. The real power comes when you combine visual mode with Vim’s operators and text objects.

The problem visual mode solves is the need to precisely select and then operate on arbitrary blocks of text. Think about editing a CSV, a JSON file, or even just a long block of code. You don’t always want to operate on a whole line, or a whole word. Sometimes you need to grab just that specific chunk.

Visual mode has three flavors:

  • v: Character-wise visual mode. This is what we used above. It selects character by character.
  • V: Line-wise visual mode. This selects entire lines. Press V and then move your cursor up or down.
  • Ctrl-v: Block-wise visual mode. This is the most powerful for structured data. It selects rectangular blocks of text.

Let’s use block-wise visual mode to change that YAML again.

Place your cursor on the d of database_host. Press Ctrl-v.

Now, press j twice to move down, highlighting the d in database_port and database_user. Then press l four times to move right, highlighting data.

database_host: localhost
database_port: 5432
database_user: admin
database_password: secret_password

You’ve selected a column of ds. Now, press c to change. Type a and press Esc.

abaserver_host: localhost
abaserver_port: 5432
abaserver_user: admin
abaserver_password: secret_password

This is incredibly useful for tabular data. You can select a column and replace it, or delete it, or even sort it (though sorting is a bit more advanced).

The core concept is that visual mode marks a region, and then you apply an operator to that marked region. The common operators are:

  • y: Yank (copy) the selected text.
  • d: Delete the selected text.
  • c: Change the selected text (deletes and enters insert mode).
  • >: Indent the selected text.
  • <: Outdent the selected text.
  • ~: Swap case of the selected text.
  • gU: Convert selected text to uppercase.
  • gu: Convert selected text to lowercase.

You can also combine operators with text objects. For example, to delete all the text within the current parentheses, you’d press vi( then d. vi( means "visual, inside parentheses, character-wise".

The real magic happens when you combine visual block mode with column editing. Imagine you have this:

foo
bar
baz

And you want to add // at the beginning of each line.

Place your cursor on the f of foo. Press Ctrl-v. Now press j twice to select the fs of foo, bar, and baz.

Press I (uppercase I) to enter "insert column" mode. Type // . Press Esc.

// foo
// bar
// baz

Vim inserts // at the beginning of the visual block selection, and then applies that insertion to every line within that block. This is a specific behavior of I and A (append column) in visual block mode.

You can also yank a visual block to a specific register. For instance, to yank the database_ prefixes into register a: highlight database_ in visual mode, then press "ay. Now you can paste this block elsewhere using "ap.

The next step is to understand how to use Vim’s macros to automate repetitive visual mode operations across many files.

Want structured learning?

Take the full Vim course →