vimtricks.wiki Concise Vim tricks, one at a time.

How do I change text in a visual block selection?

Answer

<C-v>selection c

Explanation

In visual block mode, pressing c changes (replaces) all the text in the selected rectangle. The new text you type replaces the block on every line.

How it works

  1. Select a rectangular block with <C-v> and motions
  2. Press c to delete the block and enter insert mode
  3. Type the replacement text
  4. Press <Esc> — the new text appears on all lines

Example

var x = 1;
var y = 2;
var z = 3;

Select var on all lines with <C-v>2je, press c, type let, press <Esc>:

let x = 1;
let y = 2;
let z = 3;

Tips

  • r{char} replaces the block with a single character on each position
  • C changes from the block to the end of each line
  • Block operations are powerful for columnar data
  • Use $ before c if lines have different lengths

Next

How do you yank a single word into a named register?