Skip to content
Advertisement

vim: how to copy a word in vim visual mode, but paste it in visual block mode?

I want to copy a simple text using visual mode of vim, but then paste it into multiple lines using block mode. How can I achieve this.

example:

//this all lines are commented for debug -- 
int c = 10;
int a = 2;
uint8 d = 0;
uint8 n = 0;

I want to acheive:

//this all lines are commented for debug -- 
//this all lines are commented for debug -- int c = 10;
//this all lines are commented for debug -- int a = 2;
//this all lines are commented for debug -- uint8 d = 0;
uint8 n = 0;

I tried by highlighting the comment section (using v right_arrow combination), and yanked . Now I want this yanked result to be pasted infront of all intended lines. This need not be at beginning of the line, I cant use I option to manually type the comment.

Advertisement

Answer

I would yank the first line, then go in block visual mode on the first column <C-V> and select several lines, Insert before, and paste the default register from insert mode (<c-r>"). In other words:

y$<down><home><c-v>4<down>I<c-r>"<esc>

should do the trick.

Advertisement