为什么 vim 几乎每个命令都使用寄存器?
Why does vim use registers for almost every command?
我喜欢编写具有语义意义的命令的简单性。就像,例如 cib
读起来像一个句子 change in brackets
- wonderful.
但为什么 vim 需要将旧内容复制到我的剪贴板中?我在该命令的任何地方都没有建议我要复制它,问题变得更深了。
dw
diw
等也都复制到我的 clipboard/register 中。为什么?这似乎放弃了这些命令的语义价值,我会说这是意想不到的行为。
我是不是用错了这些命令,或者有什么方法可以完全禁用此功能?目前我已经做了一些像这样的重新映射:
nnoremap dd "_dd
nnoremap cc "_cc
但我不想对每一种可能的非显式复制组合都这样做。
默认情况下,您所说的大多数命令都使用未命名的寄存器,"
。听起来你也在处理剪贴板被所有这些东西覆盖的问题,这可能是将 clipboard
设置为 unnamed
或 unnamed_plus
的症状。
要返回到标准,如果 set clipboard?
的输出是这两个选项之一,您可能可以执行 set clipboard=
。
*'clipboard'* *'cb'*
'clipboard' 'cb' string (default "autoselect,exclude:cons\|linux"
for X-windows, "" otherwise)
global
{not in Vi}
{only in GUI versions or when the |+xterm_clipboard|
feature is included}
This option is a list of comma separated names.
These names are recognized:
*clipboard-unnamed*
unnamed When included, Vim will use the clipboard register '*'
for all yank, delete, change and put operations which
would normally go to the unnamed register. When a
register is explicitly specified, it will always be
used regardless of whether "unnamed" is in 'clipboard'
or not. The clipboard register can always be
explicitly accessed using the "* notation. Also see
|gui-clipboard|.
*clipboard-unnamedplus*
unnamedplus A variant of the "unnamed" flag which uses the
clipboard register '+' (|quoteplus|) instead of
register '*' for all yank, delete, change and put
operations which would normally go to the unnamed
register. When "unnamed" is also included to the
option, yank operations (but not delete, change or
put) will additionally copy the text into register
'*'.
Only available with the |+X11| feature.
Availability can be checked with:
if has('unnamedplus')
我将提出不同意见,并建议您可能不习惯地使用 Vim。这绝不是意外行为。您是否使用 cib
作为粘贴的准备,以便 cib
搞砸了?改为 vibp
。
dw
diw
etc all copy to the my clipboard/register as well. Why? It seems like this abandons the semantic value of these commands and I would say it is unexpected behaviour.
d
然后 p
是剪切和粘贴(即移动文本)的正常 Vim 习语。这是我每天都做的操作,一天好几次,要是d
不也猛拉一下就真的很烦了。您似乎认为 d
等同于其他文本编辑器中的 Del
;它相当于 ctrl-x
(剪切)。要取消它,你会像你说的那样做 "_d
;我发现我几乎不需要它。
作为一个高级示例,c
和视觉模式 p
的默认语义使得交换两个对象变得微不足道;例如:
I drank all their food and ate all their whiskey.
转到"drank"、diw
(删除单词并拉出),转到"ate"、viwp
(select一个单词并粘贴在上面,拉出之前的内容),ctrl-o
返回到 "drank" 所在的位置和 P
(粘贴在光标前):
I ate all their food and drank all their whiskey.
(我还有一个将 "function parameter" 定义为文本对象的插件,因此如果我混淆或重构参数顺序,我会在编码中使用相同的习惯用法。)
我唯一想更普遍地防止的是可视模式下的粘贴粘贴(这样我可以多次粘贴相同的内容);为此,我使用
xnoremap <expr> P '"_d"'.v:register.'P'
(来自 here)。这仅在可视模式下重新映射 P
(在其他方面与可视模式下的 p
相同)。 p
和 P
都不是视觉模式之外的 yank,所以这不是问题。
我喜欢编写具有语义意义的命令的简单性。就像,例如 cib
读起来像一个句子 change in brackets
- wonderful.
但为什么 vim 需要将旧内容复制到我的剪贴板中?我在该命令的任何地方都没有建议我要复制它,问题变得更深了。
dw
diw
等也都复制到我的 clipboard/register 中。为什么?这似乎放弃了这些命令的语义价值,我会说这是意想不到的行为。
我是不是用错了这些命令,或者有什么方法可以完全禁用此功能?目前我已经做了一些像这样的重新映射:
nnoremap dd "_dd
nnoremap cc "_cc
但我不想对每一种可能的非显式复制组合都这样做。
默认情况下,您所说的大多数命令都使用未命名的寄存器,"
。听起来你也在处理剪贴板被所有这些东西覆盖的问题,这可能是将 clipboard
设置为 unnamed
或 unnamed_plus
的症状。
要返回到标准,如果 set clipboard?
的输出是这两个选项之一,您可能可以执行 set clipboard=
。
*'clipboard'* *'cb'*
'clipboard' 'cb' string (default "autoselect,exclude:cons\|linux"
for X-windows, "" otherwise)
global
{not in Vi}
{only in GUI versions or when the |+xterm_clipboard|
feature is included}
This option is a list of comma separated names.
These names are recognized:
*clipboard-unnamed*
unnamed When included, Vim will use the clipboard register '*'
for all yank, delete, change and put operations which
would normally go to the unnamed register. When a
register is explicitly specified, it will always be
used regardless of whether "unnamed" is in 'clipboard'
or not. The clipboard register can always be
explicitly accessed using the "* notation. Also see
|gui-clipboard|.
*clipboard-unnamedplus*
unnamedplus A variant of the "unnamed" flag which uses the
clipboard register '+' (|quoteplus|) instead of
register '*' for all yank, delete, change and put
operations which would normally go to the unnamed
register. When "unnamed" is also included to the
option, yank operations (but not delete, change or
put) will additionally copy the text into register
'*'.
Only available with the |+X11| feature.
Availability can be checked with:
if has('unnamedplus')
我将提出不同意见,并建议您可能不习惯地使用 Vim。这绝不是意外行为。您是否使用 cib
作为粘贴的准备,以便 cib
搞砸了?改为 vibp
。
dw
diw
etc all copy to the my clipboard/register as well. Why? It seems like this abandons the semantic value of these commands and I would say it is unexpected behaviour.
d
然后 p
是剪切和粘贴(即移动文本)的正常 Vim 习语。这是我每天都做的操作,一天好几次,要是d
不也猛拉一下就真的很烦了。您似乎认为 d
等同于其他文本编辑器中的 Del
;它相当于 ctrl-x
(剪切)。要取消它,你会像你说的那样做 "_d
;我发现我几乎不需要它。
作为一个高级示例,c
和视觉模式 p
的默认语义使得交换两个对象变得微不足道;例如:
I drank all their food and ate all their whiskey.
转到"drank"、diw
(删除单词并拉出),转到"ate"、viwp
(select一个单词并粘贴在上面,拉出之前的内容),ctrl-o
返回到 "drank" 所在的位置和 P
(粘贴在光标前):
I ate all their food and drank all their whiskey.
(我还有一个将 "function parameter" 定义为文本对象的插件,因此如果我混淆或重构参数顺序,我会在编码中使用相同的习惯用法。)
我唯一想更普遍地防止的是可视模式下的粘贴粘贴(这样我可以多次粘贴相同的内容);为此,我使用
xnoremap <expr> P '"_d"'.v:register.'P'
(来自 here)。这仅在可视模式下重新映射 P
(在其他方面与可视模式下的 p
相同)。 p
和 P
都不是视觉模式之外的 yank,所以这不是问题。