如何使用mg979/vim-visual-multi将多个复制的单词粘贴到目标位置
如何用vim-visual-multi批量复制多行单词并粘贴到目标位置?
问题场景
使用mg979/vim-visual-multi插件时,尝试批量复制导入语句中的变量名,粘贴到export default块中替换重复内容,但粘贴时出现错误,得到了旧的复制内容,无法达到预期效果。
预期最终代码:
import test from './test'; import test_one from './test_one'; import test_two from './test_two'; import test_three from './test_three'; import test_four from './test_four'; export default { test, test_one, test_two, test_three, test_four, };
错误原因
Vim默认使用""寄存器存储复制内容,退出多光标模式后,若有其他操作(比如移动时的误触、寄存器被其他内容覆盖),会导致粘贴的不是之前批量复制的目标内容。
正确操作流程
步骤1:完成导入语句的批量修改
按原有操作完成导入语句的修改,得到:
import test from './test'; import test_one from './test_one'; import test_two from './test_two'; import test_three from './test_three'; import test_four from './test_four'; export default { test, }
步骤2:批量复制变量名到指定寄存器
- 将光标定位到第一行
import后的test首字母t上 - 按下
ctrl+down,向下添加多光标,直到选中所有5行的变量名首字母 - 按下
viw,让每个光标选中当前行的完整变量名 - 按下
"ay,将选中内容复制到a寄存器(指定寄存器可避免被后续操作覆盖)
步骤3:在export块中批量替换内容
- 按下
Esc退出多光标模式,移动光标到export default块内的test,行 - 执行
yy4p,复制当前行并粘贴4次,生成5行重复的test,内容:
export default { test, test, test, test, test, }
- 将光标定位到第一行
test的首字母t上,按下ctrl+down添加多光标到所有5行的test首字母 - 按下
viw选中每个test单词 - 按下
"ap,从a寄存器粘贴内容,替换选中的重复单词,即可得到预期的最终代码
内容的提问来源于stack exchange,提问作者user2772197
相关产品推荐
相关产品推荐

