3

This question already has an answer here:

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?

marked as duplicate by Hotschke, statox Jul 10 at 11:58

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

2

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:

    CamelCaseACRONYMWords_underscore1234
    w--------------------------------->w
    e--------------------------------->e
    b<---------------------------------b
    

    With this plugin:

    CamelCaseACRONYMWords_underscore1234
    w--->w-->w----->w---->w-------->w->w
    e-->e-->e----->e--->e--------->e-->e
    b<---b<--b<-----b<----b<--------b<-b
    
  • 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.