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
- Select a rectangular block with
<C-v>and motions - Press
cto delete the block and enter insert mode - Type the replacement text
- 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 positionCchanges from the block to the end of each line- Block operations are powerful for columnar data
- Use
$beforecif lines have different lengths