Any way to delete in vim without overwriting your last yank?

This question already has an answer here:

  • In Vim is there a way to delete without putting text in the register? 19 answers

  • Pass to the _ register, the black hole.

    To delete a line without sticking it in the registers:

    "_dd
    

    See also :help registers .

    It's probably safest, if you want to paste something over and over again, to yank it into a "named" register.

    "aY
    

    Yanks a line into the a register. Paste it with "ap .


    Your yanked line should still be in the register 0. So do

    "0p
    

    to paste the line (and delete whenever you want)


    All yank and delete operations write to the unnamed register by default. However, the most recent yank and most recent delete are always stored (separately) in the numbered registers. The register 0 holds the most recent yank . The registers 1-9 hold the 9 most recent deletes (with 1 being the most recent).

    In other words, a delete overwrites the most recent yank in the unnamed register, but it's still there in the 0 register. The blackhole-register trick ( "_dd ) mentioned in the other answers works because it prevents overwriting the unnamed register, but it's not necessary.

    You reference a register using double quotes, so pasting the most recently yanked text can be done like this:

    "0p
    

    This is an excellent reference:

  • http://blog.sanctum.geek.nz/advanced-vim-registers/
  • 链接地址: http://www.djcxy.com/p/49474.html

    上一篇: 触摸打字员如何在vi中导航?

    下一篇: 有什么方法可以在vim中删除而不会覆盖最后一次放弃?