What's the difference between b and B in Vim?

Vim

Vim Problem Overview


I googled and that's what it says:

To go back a word, b is used. Once again, B will include more characters in what Vim considers a word.

I didn't understand what B does different from b. Can you give me an example to make it clear for me to understand? Thanks.

[EDIT]Actually I wonder this because in the online vim game, I tried to go back to WORDS from ! with b, but it didn't work. However when I tried it with Vim installed in my computer, it worked with b. So is this only for to make player use B with the help of clue?

Here is the picture of game:

enter image description here

Vim Solutions


Solution 1 - Vim

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.

So given this:

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.

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 inside vim explains this too.


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

not WORDS*!

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.

Solution 2 - Vim

B treats punctuation as part of the word, using only whitespace as word delimiters; b does not treat punctuation as part of the word.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionFigen GüngörView Question on Stackoverflow
Solution 1 - VimEeveeView Answer on Stackoverflow
Solution 2 - VimTed HoppView Answer on Stackoverflow