如何猛拉一行上的文本并将其粘贴到 Vim 中? [英] How to yank the text on a line and paste it inline in Vim?

查看:26
本文介绍了如何猛拉一行上的文本并将其粘贴到 Vim 中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

比如说,我有以下几行:

Say, I have the following lines:

thing();
getStuff();

我想使用 yy 命令获取 getStuff(),前进到 thing(),将光标放在 上(,并通过 p 命令粘贴,但由于我拉了整行,p 将粘贴 getStuff()它在哪里.

I want to take getStuff() using the yy command, go forward to thing(), placing the cursor on (, and paste via the p command, but since I yanked the whole line, p will paste getStuff() right back where it was.

我知道您可以先将光标移动到 getStuff() 行的开头,然后通过 ^D 命令从那里剪切字符,直到它的结尾 - 然后p 会做我想做的.但是,我发现输入 ^Dyy 繁琐得多.

I know you can first move the cursor to the beginning of that getStuff() line and cut the characters from there until its end via the ^D commands—then p will do what I want. However, I find typing ^D to be much more tedious than yy.

有没有办法yy,而是粘贴inline 行?

Is there a way to yy, but paste the line inline instead?

推荐答案

Use yiw ("yank internal word")而不是 yy 猛拉你想要的东西:

Use yiw ("yank inner word") instead of yy to yank just what you want:

yy 是逐行拉取,将抓取包括回车在内的整行,如果您查看未命名的寄存器(") 在 :registers 中,用作粘贴的来源.参见 :help "":

yy is line-wise yank and will grab the whole line including the carriage return, which you can see if you look at the unnamed register ("") in :registers which is used as the source for pastes. See :help "":

Vim 将未命名寄存器的内容用于任何放置命令(pP)它没有指定寄存器.此外,您可以使用名称 ".这意味着您必须输入两个双引号.写入"寄存器写入寄存器 "0.

Vim uses the contents of the unnamed register for any put command (p or P) which does not specify a register. Additionally you can access it with the name ". This means you have to type two double quotes. Writing to the "" register writes to register "0.

yiw 的另一个好处是你不必在词"的前面.你在猛拉!

An additional benefit to yiw is that you don't have to be at the front of the "word" you are yanking!

这篇关于如何猛拉一行上的文本并将其粘贴到 Vim 中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆