vim copy and replace text

前端 未结 10 2228
名媛妹妹
名媛妹妹 2021-02-14 18:02

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 lor

相关标签:
10条回答
  • 2021-02-14 18:49

    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)

    0 讨论(0)
  • 2021-02-14 18:49

    vi'y on lorem

    vi'p on ipsum

    gvy to copy back lorem to register for possible macro with vi'p

    (qa - gvy - j - vi'p - q - @a - @@ - @@ ...)

    0 讨论(0)
  • 2021-02-14 18:50

    I usually go to the sed command.

    :%s/ipsum/lorem/g
    
    • % means do this for every line
    • s means sed, or search and replace
    • g at the end means replace every ipsum with lorem; if you omit this, it only replaces the first.
    0 讨论(0)
  • 2021-02-14 18:54

    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

    0 讨论(0)
提交回复
热议问题