vim copy and replace text

2019-03-27 07:00发布

Lets say that i have this text:

$test = 'lorem';
$test2= 'ipsum';

and I want to copy lorem and paste into ipsum. I tried to do yi' on lorem and then went on ipsum and did ci' but that replaced my pastebin with ipsum. and my previous copy was lost.

10条回答
Root(大扎)
2楼-- · 2019-03-27 07:25

Go to the l of lorem, ye (yank to end of word). Go to the i of ipsum, "_de (delete to end of word, putting the deleted text in the black hole register. P (paste register before cursor).

Altogether: yej"_deP

查看更多
疯言疯语
3楼-- · 2019-03-27 07:25

I'm not sure what do you want exactly.

You have this on two lines:

$test = 'lorem';
$test2= 'ipsum';

If you go to l and yw, it yanks lorem, then go to i of ipsum, and cw, and p and it will replace ipsum with lorem. You will still have both lorem and ipsum in the registers.

You can get the contents of those registers with :reg

If you want to paste something from them then "*p, or ":p, or "0p (you'll see it when you type :reg)

查看更多
老娘就宠你
4楼-- · 2019-03-27 07:26

yi' on lorem, move to i of ipsum, vep?

查看更多
淡お忘
5楼-- · 2019-03-27 07:30

Easy:

"kyi' on lorem, move to i of ipsum, ve"kp

This yanks lorem into register k, pastes it over ipsum from register k, and keeps it in register k ready to paste again anywhere else you might want to put it. ipsum still ends up in the default register, but that's no longer a problem and could be useful too.

If you've already got something in register k, you can use a different register instead (just use a different key).

查看更多
登录 后发表回答