Vim 文档中有 Inclusive 和 Exclusive 的表达,但是在用法上难以找到关联两者的一致性。
比如 f 和 F 在 vim 文档中,前者是 inclusive 的,后者是 exclusive 的。
f{char} To [count]'th occurrence of {char} to the right. The
cursor is placed on {char} |inclusive|.
F{char} To the [count]'th occurrence of {char} to the left.
The cursor is placed on {char} |exclusive|.
Demo
使用 f 和 F 处理以下文本
hello world.
假设光标在 ^ 位置,按照以上文档的说明
使用 fw 时,因为 f 是 inclusive 的,所以光标会移动到 w
hello world.
^
✅ hello world.
^
使用 Fw 时,因为 F 是 exclusive 的,所以光标会移动到 o ?
wait, 真的是这样吗?不,答案是会移动到 w
这是因为,vim 中的 exclusive 和 inclusive 是对于 vim motion 最后一个字符的约束,而对于反向 motion (F) 而言,最后一个字符是 .
hello world.
^
❌ hello world.
^
✅ hello world.
^
可以用 dFw 命令证明这一点。可以看出 . 被保留了,因为 F 是 Exclusive 的
hello world.
^
hello .
^
Conclusion
在 vim 中 exclusive 和 inclusive 约束的是 motion 对最后一个字符的行为,但需要注意区分 motion 的方向
-
正向 motion ( f ), 最后一个字符是 motion 最后一个字符
-
反向 motion ( F ), 最后一个字符是 motion 开始第一个字符