How do I change the same column of text across multiple lines at once?
Answer
<C-v>jjc replacement<Esc>
Explanation
Visual block mode's change command lets you replace a rectangular column of text across multiple lines in a single operation. Select a block with <C-v>, extend it vertically and horizontally, then press c to delete the block and enter insert mode. Whatever you type replaces the selected column on every line when you press <Esc>.
How it works
<C-v>enters visual block mode- Use motions like
j,k,l,h,w,e,f{char}to shape the rectangular selection cdeletes the selected block and enters insert mode on the first line- Type your replacement text
- Press
<Esc>— Vim applies the same replacement to every line in the block selection
The replacement text appears on only the first line while you are typing. The multi-line effect is applied the moment you press <Esc>.
Example
Given the text:
var alpha = 1;
var beta = 2;
var gamma = 3;
var delta = 4;
To change var to let on all four lines: place the cursor on the v of the first var, press <C-v>3je to select the word var on all four lines, then press c, type let, and press <Esc>:
let alpha = 1;
let beta = 2;
let gamma = 3;
let delta = 4;
All four lines are changed simultaneously.
Tips
- Use
<C-v>withf{char}to select up to a specific character:<C-v>3jf=selects from the cursor to the=on each line - If the replacement text is shorter or longer than the selected block, Vim adjusts each line accordingly
- Use
r{char}instead ofcto replace every character in the block with a single character without entering insert mode <C-v>jjjIinserts at the left edge of the block, while<C-v>jjjAappends at the right edge — usecwhen you want to replace the selected area- The change only appears on the first line while typing — don't worry, all lines update when you press
<Esc> - Combine with
oin visual block mode to toggle the cursor to the opposite corner of the selection, useful for adjusting the block before pressingc