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

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


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.


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