vim – 如何在多行代码中插入多行代码?

前端之家收集整理的这篇文章主要介绍了vim – 如何在多行代码中插入多行代码?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在从许多不同的数据源做一些剪切和粘贴.我试图在多行代码中插入多行代码,以便粘贴代码的第一行在原始代码的两个特定点之间进行,对于第二行则相同,依此类推.这类似于在分割的多行代码之间插入代码块.下面的图片.gif显示了我的意思:

我怎样才能做到这一点?我正在尝试使用VIM CTRL V,但我无法粘贴多行代码.

这是样本:

VIOLET=SpectralBand([0.380,0.450],'violet')
BLUE=  SpectralBand([0.450,0.495],'b')
GREEN= SpectralBand([0.495,0.570],'g')
YELLOW=SpectralBand([0.570,0.590],'y')
ORANGE=SpectralBand([0.590,0.620],'orange')
RED=   SpectralBand([0.620,0.750],'r')

"viol3et",45839,"bl3ue",43903,"gre3en",28392,"y3ellow",23049,"o3range",12389,"r3ed",32840,
您应该使用光标选择左上角,键入Control V,然后转到最后一行,并键入$以获取所有行的结尾(在其他答案中这是错过的).
然后用d删除,转到目的地,然后使用p.

对于您的确切样本,vim中的解决方案是:

G0<c-v>{j$dggf(p

分解为:

G     go to last line of file
0     go to its first character
<c-V> to start a blockwise selection
{     go to prevIoUs empty line
j     go to next line (hence the beginning of block)
$    extend the blockwise selection to end of ALL lines (that was my point)
d     delete and store the block
gg    go to first line of file
f(    go to next character '(' if on same line.
p     to paste the block after the column of current character.

$的替代方法是启用

:set virtualedit=all

如果您不能将光标放在目的地(超出其行尾),那么这将完成工作.

原文链接:https://www.f2er.com/bash/385020.html

猜你在找的Bash相关文章