How do I change the case of a specific column of text using visual block mode?
Answer
<C-v>jjlU
Explanation
Visual block mode lets you select rectangular regions of text, which means you can target a specific column and apply case changes only to that area. This is extremely useful when working with tabular data, CSV files, or any aligned text where you need to uppercase or lowercase specific columns without affecting the rest of the line.
How it works
<C-v>— enters visual block mode, allowing rectangular selectionjj— extends the selection down two lines (use as manyjpresses as needed)l— extends the selection one column to the right (adjust width as needed)U— converts all selected characters to uppercase
You can substitute U with u for lowercase or ~ to toggle case.
Example
Before (cursor on the j of john):
john,doe,engineer
jane,smith,designer
jack,lee,manager
After pressing <C-v>jjlU:
JOhn,doe,engineer
JAne,smith,designer
JAck,lee,manager
Only the first two characters of each line were uppercased because the block selection was two columns wide.
Tips
- Use
$instead oflto extend the block to the end of each line - Combine with motions like
f,to select up to a delimiter, then applyUoru - Use
gUandguas operators outside of visual mode for motion-based case changes:gUiwuppercases the current word