vimtricks.wiki Concise Vim tricks, one at a time.

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 position
  • P — 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 P to paste before the cursor for more precise placement
  • Combine with "a to use a named register: "ax then "ap
  • After pasting, use gv to reselect the pasted block for further adjustments

Next

How do I return to normal mode from absolutely any mode in Vim?