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

前端 未结 2 1101
野的像风
野的像风 2020-12-25 09:26

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 underst

相关标签:
2条回答
  • 2020-12-25 10:04

    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.

    0 讨论(0)
  • 2020-12-25 10:04

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

    0 讨论(0)
提交回复
热议问题