How do I use vim registers?

后端 未结 17 2142
一向
一向 2020-11-27 08:58

I only know of one instance using registers is via CtrlR* whereby I paste text from a clipboard.

What are other uses of registers?

17条回答
  •  天命终不由人
    2020-11-27 09:31

    A big source of confusion is the default register ". It is important to know the way it works. It is much better if the default register is avoided most of the times. The explanation from the Vim documentation:

    Vim fills this register with text deleted with the "d", "c", "s", "x" commands
    or copied with the yank "y" command, regardless of whether or not a specific
    register was used (e.g.  "xdd).  This is like the unnamed register is pointing
    to the last used register.
    

    So the default register is actually a pointer to the last used register. When you delete, or yank something this register is going to point to other registers. You can test that by checking the registers. There is always another register that is exactly the same as the default register: the yank register ("0) , the first delete register("1) , small delete register("-) or any other register that was used to delete or yank.

    The only exception is the black hole register. Vim doc says:

    An exception is the '_' register: "_dd does not store the deleted text in any
    register.
    

    Usually you are much better off by using directly: "0, "- and "1-"9 default registers or named registers.

提交回复
热议问题