如何在 Vim 中复制一个单词并将其粘贴到另一个单词上?

发布于 2024-12-10 22:30:32 字数 119 浏览 0 评论 0原文

我知道如何复制一个单词,但我似乎覆盖了剪贴板中的内容,因为当我尝试复制一个单词时,它似乎不起作用。

要复制单词,我可以使用

bye

如何复制单词?

I know how to copy a word, but I seem to overwrite what is in my clipboard because, when I try to copy over a word, it does not seem to be working.

To copy a word, I can use

bye

How to copy over a word?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(8

倾`听者〃 2024-12-17 22:30:32

也许您只想这样做:

viwp

这将直观地选择一个新单词,然后粘贴到它上面。

现在,如果你不想在执行此操作时丢失寄存器,你也可以放入你的 vimrc:

xnoremap p pgvy

Perhaps you just want to do this:

viwp

which will visually select a new word, and paste over it.

Now, if you don't want to lose your register when doing this, you can also put in your vimrc:

xnoremap p pgvy
手心的海 2024-12-17 22:30:32

像往常一样复制源单词(例如,使用 yiw)并用于

viw"0p

粘贴到目标单词。

由于可视模式下的 p 命令(请参阅 :help v_p)不会改变
编号寄存器0 包含最近的文本
yank 命令,可以反复粘贴相同的复制单词。

Copy the source word as usual (e.g., with yiw) and use

viw"0p

to paste over the destination word.

Since the p command in Visual mode (see :help v_p) does not alter
the numbered register 0 containing the text from the most recent
yank command, the same copied word can be pasted over and over again.

谁的年少不轻狂 2024-12-17 22:30:32

执行此操作一次:

ciw0

然后,要始终使用您提取的文本替换单词,请执行以下操作:

.

您可以像这样使用搜索:

/foo< ;Cr>

.nnn

它之所以有效,是因为:

ciw 替换内部单词,并且

0 使用最近拉出的寄存器来替换它,然后也使用 .

遗憾的是,如果您直观地选择要替换的文本并使用 .,则此方法不起作用。

请注意,如果您最初使用视觉选择来选择要替换的文本并执行了 c0 ,那么之后 . 将替换与中包含的相同长度的字符视觉选择。

Do this once:

ciw<C-r>0

Then to replace words always using the text you yanked do:

.

You can use search with it like this:

/foo<Cr>

.n.n.n

It works because:

ciw replaces inner word and

<C-r>0 uses the most recently yanked register to replace it, which . then also uses.

Sadly, this does not work if you visually select text you wish to replace and use ..

Note that if you originally used visual selection to select the text to replace and did c<C-r>0 then after that . will replace the same length of characters as was included in the visual selection.

不离久伴 2024-12-17 22:30:32

您可以使用寄存器 0,其中包含刚刚覆盖的“剪贴板”文本。对于您的示例,您可以拉出要粘贴的文本,将光标放在单词“bye”中的某处,然后输入

ciw [cut in word;删除光标下的单词并进入插入模式]

ctrl-r 0 [register 0;从寄存器 0 粘贴文本]

您可以使用 :disp 查看所有寄存器中的内容。正如 Daenyth 所说,您可以使用 "x[del/cut/yank command] 拉入特定寄存器,并在命令模式下使用 "xp 或 ctrl 粘贴-r x 来自插入/替换。

You could use register 0, which contains the just-overwritten "clipboard" text. For your example, you could yank the text to paste, put the cursor somewhere in the word "bye", and type

ciw [cut in word; deletes the word under the cursor and goes to insert mode there]

ctrl-r 0 [register 0; paste text from register 0]

You can see what's in all the registers with :disp. As Daenyth says, you can yank into a particular register with "x[del/cut/yank command] and paste with "xp from command mode, or ctrl-r x from insert / replace.

沙沙粒小 2024-12-17 22:30:32

当您删除一个单词时,它会被放入 " 寄存器中,这是用于粘贴的默认寄存器,因此当您删除要替换的单词时,它将取代 中前一个单词的位置” 注册。但是,前一个单词将在寄存器 0 中,前一个单词将在 1 中,依此类推 - 您可以随时通过运行 :reg 并查看寄存器的内容。因此,要替换单词,您可以首先复制第一个单词(yiw),然后“更改”要替换的单词(ciw),然后从寄存器插入<通过按ctrl-r0,code>0。 (您也可以先删除单词 (diw),然后从寄存器 0 中粘贴:"0p

When you delete a word it is put in the " register which is the default register for pasting, so when you delete the word you want to replace, it will take the previous word's place in the " register. However, the previous word will be in register 0, the one before in 1 and so on – you can at any time see this by running :reg and see the registers' contents. So, to replace a word you can first copy the first word (yiw), then “change” the word you want to replace (ciw) and then insert from register 0 by hitting ctrl-r, 0. (You could also first delete the word (diw) and then paste from register 0: "0p.

无人接听 2024-12-17 22:30:32

简单的解决方案是相反:首先粘贴新单词,然后删除旧单词。

The easy solution is to do it the other way around: first paste the new word, then delete the old one.

我很OK 2024-12-17 22:30:32

yiw - 复制单词
ciw - 剪切一个单词

然后将光标移到要粘贴的位置并按 p

yiw - Copies a word
ciw - Cuts a word

Then take the cursor wherever you want to paste and press p

归途 2024-12-17 22:30:32

您可以通过在寄存器前面添加"a(其中a是寄存器的名称)来yank到寄存器中。请参阅如何使用 vim 寄存器

b"aye

You can yank into a register by prepending it with "a (where a is the name of the register). See How to use vim registers

b"aye

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文