Let's consider an example where the cursor is at the beginning of the text one_two three.

  • Underscores are treated as part of the word, so w moves right to the first letter of three.

  • With set iskeyword-=_ the underscore is a separate word, so w moves to the underscore.

  • Instead, I'd like w to treat the underscore as whitespace, moving to the first letter of two.

How can I configure Vim to get the third of these behaviors?


Plugins vim-wordmotion or camelcasemotion

I do not know how vim can be configured to do this out of the box. There is a related wikipage: https://vim.fandom.com/wiki/Moving_through_camel_case_words

This wikipage points you to following plugins:

  • vim-wordmotion

    Under Vim's definition of a word:


    With this plugin:

  • camelcasemotion (#1905), despite its name, also supports snake_case.
    This plugin defines new mappings ,w ,b and ,e. I use ;/, for repeating fFtT and other motions with the help of repmo-vim. As always you can define your own ones, e.g. redefine the builtin ones or choose those which you think are a good pick:

    map w <Plug>CamelCaseMotion_w 
    map b <Plug>CamelCaseMotion_b 
    map e <Plug>CamelCaseMotion_e 
    sunmap w 
    sunmap b 
    sunmap e

Not the answer you're looking for? Browse other questions tagged or ask your own question.