How do I toggle the case of a rectangular column region across multiple lines?
Answer
<C-v>{motion}~
Explanation
Visual block mode (<C-v>) selects a rectangular column region, and pressing ~ at the end toggles the case of every character in that exact column range across all selected lines. This is useful for bulk transformations of aligned data — such as switching column headers, toggling the case of a prefix or suffix, or manipulating fixed-width records.
How it works
<C-v>enters Visual Block mode{motion}extends the selection (e.g.,jj3lfor three lines down and four columns wide)~toggles case for every character in the selected rectangle
Unlike gU (uppercase all) or gu (lowercase all), ~ flips: lowercase becomes uppercase and uppercase becomes lowercase, character by character.
Example
Given the text:
name: alice
name: bob
name: carol
With the cursor on a in alice, enter <C-v>2j4l~:
name: ALICE
name: BOB
name: CAROL
Tips
- Combine with
$to extend to end of line:<C-v>2j$~toggles case from the cursor to EOL on each line - Use
gUin visual mode to force uppercase;guto force lowercase — when you need a deterministic outcome rather than a toggle - This works in all three visual modes (
v,V,<C-v>), but the column precision of block mode makes it uniquely powerful for aligned data