学习到了 Vim 中的一个新概念: exclusive 和 inclusive

2019-05-18 08:22:29 +08:00
 jdhao

如果你经常使用 dwde,你会发现两者的表现不太一致,另外 db 并不能删除当前光标所在处的字符,很蛋疼,为什么是这样呢?原来和 Vim 中一个动作的 exclusivity 有关。

认真学习了一下,写了一篇短文: https://jdhao.github.io/2019/05/18/nvim_exclusive_inclusive_motion/

不知道有多少人不知道的,欢迎讨论。。

4680 次点击
所在节点    Vim
14 条回复
vitovan
2019-05-18 08:28:13 +08:00
学习了,虽然没看太明白,VIM 太难了
jdhao
2019-05-18 08:31:39 +08:00
@vitovan 哪里没明白。。这个这是一个简单的概念哈~
carlclone
2019-05-18 08:55:01 +08:00
通常使用 ciw 删除和修改
conanforever22
2019-05-18 08:58:47 +08:00
学习了, 平时用 df{char} / dt{char} , 看 help 发现 f{char}/t{char}都是 inclusive, 加了 v 可以转换为 exclusive
thedrwu
2019-05-18 09:03:05 +08:00
手指对着空气比划了一下才想起来 dw 和 de 有什么区别。
跟形码输入汉字一样,成为了肌肉记忆之后看着字母不知道它要干什么。。
jdhao
2019-05-18 09:16:20 +08:00
@conanforever22 自带的 f 只能找一个字符,不精确,我用 vim-sneak 代替,可以找两个字符,精确度大大提升,基本上三个按键跳到眼睛能看到的任何地方
shaco
2019-05-18 09:17:19 +08:00
@jdhao #2 为啥我觉得 de 才是 exclusive,dw 才是 inclusive。因为根据这两个单词的意思,exclusive 的意思应该是把最后一个字符排除在外,也就是不删除最后一个字符。而 inclusive 应该是删除最后一个字符
jdhao
2019-05-18 09:27:19 +08:00
@shaco 你还没理解正确,以 de 为例,e 跳到 hello 的 o 处,因为 e 是 inclusive,所以从 h 到 o 的所有字符都被删除了,如果 e 是 exclusive,那么字符 o 不会被删除
vitovan
2019-05-18 10:09:31 +08:00
@shaco
@jdhao

我把这个贴到这里,可能会帮助理解:

```
Many commands that text are made from an operator and a motion.
The format for a follows:

d motion

Where:
d - is the delete operator.
motion - is what the operator will operate on (listed below).

A short list of motions:
w - until the start of the next word, EXCLUDING its first character.
e - to the end of the current word, INCLUDING the last character.
$ - to the end of the line, INCLUDING the last character.
```
vitovan
2019-05-18 10:11:25 +08:00
然后,我想我理解了,谢谢楼主。
jdhao
2019-05-18 10:20:59 +08:00
@vitovan 有 vim 的话上手用一下,结合文档,就比较容易明白这个概念
mrvon
2019-05-18 11:07:50 +08:00
仔细一想, dw, de 两个命令中,w, e 两个 motion 与 d 结合之后,行为不一致了。为了适应使用者的直觉,所以搞了 exclusive 和 inclusive。感谢分享。
mrcode
2019-05-18 15:13:52 +08:00
一般习惯用 df* 和 dt*
jciba5n4y6u
2019-05-18 21:31:43 +08:00
dw 经常用,de 没用过。

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/565250

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX