我只知道使用寄存器的一个实例是通过CtrlR*,从中我从剪贴板粘贴文本。

寄存器的其他用途是什么?如何使用它们?

你所知道的关于VI寄存器的一切(让我们关注VI 7.2)——分享给我们。


当前回答

一个很酷的技巧是使用“1p粘贴最后删除/更改(,然后使用。重复粘贴后续删除的内容。换句话说,“1p…基本上相当于"1p"2p"3p"4p。

你可以用它来倒序一些行: dddddddddd“1 p…

其他回答

来自vim的帮助页面:

CTRL-R {0-9a-z"%#:-=.}                  *c_CTRL-R* *c_<C-R>*
        Insert the contents of a numbered or named register.  Between
        typing CTRL-R and the second character '"' will be displayed
        <...snip...>
        Special registers:
            '"' the unnamed register, containing the text of
                the last delete or yank
            '%' the current file name
            '#' the alternate file name
            '*' the clipboard contents (X11: primary selection)
            '+' the clipboard contents
            '/' the last search pattern
            ':' the last command-line
            '-' the last small (less than a line) delete
            '.' the last inserted text
                            *c_CTRL-R_=*
            '=' the expression register: you are prompted to
                enter an expression (see |expression|)
                (doesn't work at the expression prompt; some
                things such as changing the buffer or current
                window are not allowed to avoid side effects)
                When the result is a |List| the items are used
                as lines.  They can have line breaks inside
                too.
                When the result is a Float it's automatically
                converted to a String.
        See |registers| about registers.  {not in Vi}
        <...snip...>

我认为秘密的大师寄存器是表达式= register。它可以用于创建映射。

:inoremap  \d The current date <c-r>=system("date")<cr>

您可以将它与您的系统结合使用,或者从自定义VimL函数等获得响应。

或者只是一些特别的东西

<c-r>=35+7<cr>

我使用默认寄存器在我的vim窗口中为文本grep,而不必伸手去拿鼠标。

把文本 :!grep " < CTRL-R > 0 " < CR >

Vim中的寄存器允许您对存储在其中的文本运行操作或命令。要访问寄存器,在命令前键入“a”,其中a是寄存器的名称。如果你想把当前的行复制到寄存器k中,你可以输入

"kyy

或者你也可以使用大写字母来添加到寄存器中

"Kyy

然后,您可以使用

"kp

从Linux上的系统剪贴板粘贴

"+p

从Windows上的系统剪贴板粘贴(或从Linux上的“鼠标突出显示”剪贴板粘贴)

"*p

访问当前定义的所有寄存器类型

:reg

Q5记录编辑到寄存器5(下一个q停止记录) :reg显示所有寄存器和其中的任何内容 @5执行注册5宏(已录制的编辑)