vim:将块粘贴到块旁边
我得到了这个
______0______
/ \
__7__ __3__
/ \ / \
0 4 9 8
/ \ / \ / \ / \
7 7 0 4 6 0 3 2
______another______
/ \
__block__ __just__
/ \ / \
aside the first one
,我想
______0______ ______another______
/ \ / \
__7__ __3__ __block__ __just__
/ \ / \ / \ / \
0 4 9 8 aside the first one
/ \ / \ / \ / \
7 7 0 4 6 0 3 2
在 vim 中是否有一种“多行块”复制/剪切和粘贴?
I got this
______0______
/ \
__7__ __3__
/ \ / \
0 4 9 8
/ \ / \ / \ / \
7 7 0 4 6 0 3 2
______another______
/ \
__block__ __just__
/ \ / \
aside the first one
I'd like that
______0______ ______another______
/ \ / \
__7__ __3__ __block__ __just__
/ \ / \ / \ / \
0 4 9 8 aside the first one
/ \ / \ / \ / \
7 7 0 4 6 0 3 2
Is there kind of "mutliline block" copy/cut and paste in vim ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
没有什么神奇的方法可以实现这一点,但通过
:help Visual-block
和一些规划是可以实现的。首先,使用视觉块模式的简单方法:
将光标放在包含
另一个
的行的第一列上。按
进入视觉块模式,然后按jjjj
向下扩展块,按$
将其扩展为每行的末尾。用
d
剪切它。将光标移动到包含
0
的行末尾,然后按p
放置刚刚剪切的内容。恐怖:
<前><代码> ______0______ ______另一个______
//\ \
__7__ _ __块__ __只是__ _3__
/ \ / / \ / \ \
0 4 9 除了第一个 8
/ \ / \ / \ / \
7 7 0 4 6 0 3 2
问题在于“块文本”(由于缺乏更好的词)是“就地”完成的,没有添加填充或假设任何有关用户意图的信息。
为了将该“块文本”放在正确的位置,您需要自己添加一些填充:
将光标放在包含
另一个
的行的第一列上。按
进入视觉块模式,然后按jjjj
向下扩展块,按$
将其扩展为每行的末尾。用
d
剪切它。将光标移至包含
0
的行末尾,使用A
添加所需数量的空格,然后按p
放置刚刚剪切的内容。好多了:
<前><代码> ______0______ ______另一个______
/ \ / \
__7__ __3__ __块__ __just__
/ \ / \ / \ / \
0 4 9 8 除了第一个
/ \ / \ / \ / \
7 7 0 4 6 0 3 2
注意:
:help 'virtualedit'
也很有用,但它可能需要特别小心,所以我更喜欢手动添加填充的简单性。There is no magical way to achieve that but it is doable with
:help visual-block
and some planning.First, the naive approach, with visual-block mode:
Put the cursor on the first column of the line containing
another
.Press
<C-v>
to enter visual-block mode, thenjjjj
to expand the block downward, and$
to expand it to the end of each line.Cut it with
d
.Move the cursor to the end of the line containing
0
and pressp
to put what you just cut.The horror:
The problem is that putting "block text" (by lack of a better word) is done "in place", without adding padding or assuming anything about the user's intent.
In order to put that "block text" at the right position, you need to add some padding yourself:
Put the cursor on the first column of the line containing
another
.Press
<C-v>
to enter visual-block mode, thenjjjj
to expand the block downward, and$
to expand it to the end of each line.Cut it with
d
.Move the cursor to the end of the line containing
0
, append as many spaces as necessary withA<Space><Space><Space>
, and pressp
to put what you just cut.Much better:
NOTE:
:help 'virtualedit'
can be of use, too, but it can necessitate special care so I prefer the simplicity of adding padding manually.