How do I move a column of text to a different position using visual block mode?
Answer
<C-v>jjxp
Explanation
Visual block mode lets you select, cut, and paste rectangular columns of text. By selecting a column with <C-v>, cutting it with x or d, moving to the target position, and pasting with p, you can rearrange columnar data effortlessly.
How it works
<C-v>jj— select a vertical block (column)x— cut the selected block- Move cursor to the destination column
p— paste the block after the cursor positionP— paste the block before the cursor position
Example
Before:
AAA BBB CCC
AAA BBB CCC
AAA BBB CCC
Select 'BBB' column, cut with x, move to after CCC, paste with p:
AAA CCC BBB
AAA CCC BBB
AAA CCC BBB
Tips
- Block paste inserts as a rectangle, preserving column alignment
- Use
Pto paste before the cursor for more precise placement - Combine with
"ato use a named register:"axthen"ap - After pasting, use
gvto reselect the pasted block for further adjustments