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

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

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


当前回答

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

其他回答

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

"kyy

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

"Kyy

然后,您可以使用

"kp

从Linux上的系统剪贴板粘贴

"+p

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

"*p

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

:reg

黑洞寄存器_是寄存器中的/dev/null。

我在我的vimrc中使用它来允许删除单个字符而不更新默认寄存器:

noremap x "_x

并且在不更新默认寄存器的情况下以可视模式粘贴:

vnoremap p "_dP

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

如果你想在ex-mode命令中粘贴寄存器的内容,点击<C-r><寄存器字母>。

你为什么要用这个?我想对一个较长的字符串进行搜索和替换,所以我在可视模式下选择了它,开始输入搜索/替换表达式:%s/[PASTE YANKED PHRASE]//g,然后继续我的一天。

如果你只想在ex模式下粘贴一个单词,可以在进入ex模式前确保光标在它上面,然后在ex模式下点击<C-r><C-w>来粘贴单词。

为了更方便:

cnoremap <c-g> <c-r>"
cnoremap <C-Right> <c-r><c-w>

我最喜欢的特性是能够使用大写字母追加到寄存器中。例如,假设您想要将导入的一个子集从缓冲区X移动到缓冲区Y。

到缓冲区X中的x1行。 输入“ayy”以将寄存器a替换为行x1的内容。 到第x5行。 输入“Ayy(大写A)以在寄存器A的末尾追加行x5。 转到缓冲区Y,输入“ap”进行粘贴

<content of line x1>
<content of line x5>