How do I delete from a visual block column to the end of each selected line?
Answer
C (visual-block)
Explanation
In visual block mode, pressing C (uppercase) deletes from the leftmost column of the selection to the end of every selected line, then drops you into insert mode. Whatever you type is replicated across all affected lines simultaneously — the same behaviour as visual block c, but the deletion extends to end-of-line rather than being limited to the width of the block.
How it works
<C-v>enters visual block mode- Select rows with
j/kand optionally adjust the starting column withh/l C— analogous to normal-modeC("change to end of line") — deletes from the block's left edge to EOL on every row and starts insert mode- Type your replacement text; it appears on the first line
- Press
<Esc>to apply the change to all selected rows
Example
Given these lines where you want to replace everything after a certain column:
foo_bar = old_value_one
foo_baz = old_value_two
foo_qux = old_value_three
Place the cursor at the = column on line 1, select 2 more rows with <C-v>2j, then press C and type = REMOVED followed by <Esc>:
foo_bar = REMOVED
foo_baz = REMOVED
foo_qux = REMOVED
Tips
- Contrast with lowercase
cin visual block:conly replaces the highlighted rectangle;Calways extends to end-of-line - Useful when lines have ragged endings that you want to normalise
Din visual block works similarly but deletes to EOL without entering insert mode- To insert text at the start of each line instead, use
I(visual block insert)