首页 > 解决方案 > vim:如何在 vim 可视模式下复制单词,但在可视块模式下粘贴?

问题描述

我想使用 vim 的可视模式复制一个简单的文本,然后使用块模式将其粘贴到多行中。我怎样才能做到这一点。

例子:

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

我想实现:

//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;

我尝试突出显示评论部分(使用 v right_arrow 组合),然后猛拉 . 现在我希望将这个被拉出的结果粘贴到所有预期行的前面。这不必在行首,我不能使用 I 选项手动输入注释。

标签: linuxvim

解决方案


我会拉出第一行,然后在第一列上进入块可视模式<C-V>并选择几行,Insert before,然后从插入模式(<c-r>")粘贴默认寄存器。用顺序的话:

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

应该做的伎俩。


推荐阅读