且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Vim 中的 b 和 B 有什么区别?

更新时间:2022-06-22 05:39:43

像大多数大写移动对一样,b 按单词移动,但 B 按单词移动.不同之处在于,vim 将单词"视为字母、数字和下划线(您可以使用 iskeyword 设置对其进行配置),但WORD"总是 任何不是空白的东西.

Like most of the capitalized movement pairs, b moves by word, but B moves by WORD. The difference is that vim considers a "word" to be letters, numbers, and underscores (and you can configure this with the iskeyword setting), but a "WORD" is always anything that isn't whitespace.

鉴于此:

foo-bar-baz

如果您的光标在 z 上并按下 b,光标将移回 baz 的开头,然后移动到连字符,然后回到 bar 的开头,依此类推.每个对 vim 来说都是不同的词":foo-bar-baz.

If your cursor is on the z and you press b, the cursor will move back to the start of baz, then to the hyphen, then back to the start of bar, and so on. Each of these is a different "word" to vim: foo, -, bar, -, baz.

但是如果你按下B,光标会一直向左移动到f,因为foo-bar-baz非空白,因此是单个 WORD.

But if you press B, the cursor will move all the way left to the f, because foo-bar-baz is all non-whitespace and thus a single WORD.

:help word 在 vi​​m 中也解释了这一点.

:help word inside vim explains this too.

关于 vim 游戏:我认为游戏将巨石视为标点符号.尝试像这样在 vim 中输入它:

Regarding the vim game: I think the game treats boulders as punctuation. Try typing it in vim like this:

not WORDS*!

将光标放在 ! 上,b 会将您移回 *,因为 *! 是所有标点符号,因此一个词.但是那个 * 实际上是一块巨石,所以你不能移动到那里,所以什么也没发生.另一方面,B 会跳过所有不是空格的内容.

With the cursor on !, b will move you back to the *, because *! is all punctuation and thus one word. But that * is actually a boulder, so you can't move there, so nothing happens. B, on the other hand, will skip you back over everything that isn't a space.