How do I yank and paste a vertical block of text using blockwise registers?
Answer
<C-v>jj"ay then "ap
Explanation
How it works
Vim registers remember not just the text content but also the type of selection that was used to yank it: characterwise, linewise, or blockwise. When you yank text using visual block mode (Ctrl-V), the register stores it as a blockwise selection. When you paste it, the text is inserted as a vertical column rather than inline.
The sequence <C-v>jj"ay breaks down as:
<C-v>-- enter visual block modejj-- extend the selection down two lines (adjust as needed)"ay-- yank the block selection into registera
When you later paste with "ap, the text is inserted as a column to the right of the cursor, pushing existing text on each line to the right. Using "aP inserts the column to the left of the cursor.
This is fundamentally different from linewise or characterwise paste. A blockwise paste affects multiple lines simultaneously, inserting text at the same column position on each line.
Example
Suppose you have a table and want to duplicate a column:
Alice 100
Bob 200
Carol 300
- Position cursor on
1in100 - Enter visual block mode:
<C-v> - Select the number column:
jj$ - Yank into register
a:"ay - Move to the end of line 1:
$ - Paste:
"ap
Result:
Alice 100 100
Bob 200 200
Carol 300 300
You can also change the register type after the fact using setreg(). For example, call setreg('a', @a, 'b') converts register a to blockwise. This lets you paste characterwise text as a block column, which is a powerful transformation technique.