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

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

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


当前回答

其他有用的寄存器:

“*”或“+ -”系统剪贴板的内容

/ -最后一次搜索命令

:—最后一个命令行命令。

注意,对于vim宏,您可以编辑它们,因为它们只是记录宏时使用的击键列表。因此,您可以将宏写入文本文件(使用“ap”来编写宏a)并编辑它们,并使用“ay$”将它们加载到寄存器中。存储有用宏的好方法。

其他回答

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

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

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

来自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...>

我的朋友布莱恩写了一篇关于这方面的全面文章。我认为这是一个很好的介绍如何使用主题。https://www.brianstorti.com/vim-registers/

我最喜欢的寄存器是':'寄存器。在正常模式下运行@:可以重复之前运行的ex命令。

所以我们可以用MY_commandXXXXX来验证一些命令,然后把MY_commandXXXXX放在vimrc中