为什么 c/_<CR> 的行为与 cf_ 不同?

Why does c/_<CR> behave differently from cf_?

假设我的缓冲区中有文本 some_func,我的光标位于 s

如果我键入 c/_<CR>(其中 <CR> 代表 [Enter] 键),它会删除文本 some 并进入插入模式。如果我键入 cf_,它会删除文本 some_ 并进入插入模式。区别在于 / 保留 _,但 f 将其删除。

然而,/_<CR>f_ 的行为相同(都将光标移动到下划线),那么为什么它们对 c 命令的工作方式不同?有什么方法可以配置 Vim 使它们保持一致吗?

实际上,即使下一个 _ 在不同的行上,c/_⏎ 也会更改为下一个 _,而 cf_ 如果有,则什么都不做该行的其余部分没有 _。这似乎只是 / 用作动议时的一个怪癖;在这种情况下,它更像是 t 而不是 f.

:help / 说:

Search forward for the [count]'th occurrence of {pattern} |exclusive|.

:help f说:

To [count]'th occurrence of {char} to the right. The cursor is placed on {char} |inclusive|.

在光标位于 |exclusive]|inclusive| 上时按 <C-]> 会导致 :help exclusive,即:

A character motion is either inclusive or exclusive. When inclusive, the start and end position of the motion are included in the operation. When exclusive, the last character towards the end of the buffer is not included.

请注意,这仅涉及操作员之后使用的动作,c 在这种情况下,而不是用于移动光标的独立动作。查看 :help operator 以更深入地了解运算符和动作如何交互。