Customising word separators in vi

前端 未结 6 1523
抹茶落季
抹茶落季 2020-12-04 23:24

vi treats dash - and space   as word separators for commands such as dw and cw.

Is there a way to add unders

相关标签:
6条回答
  • 2020-12-04 23:46

    I was just looking at this myself and added this to my .vimrc:

    set iskeyword=!-~,^*,^45,^124,^34,192-255,^_
    

    My .vimrc had issues with ^| and ^", which was part of the default iskeyword for my setup, so I changed to their ascii values and it works fine. My main modification was to add "^_" to the end of the default setting to keep vim from seeing underscore as being part of a word.

    0 讨论(0)
  • 2020-12-04 23:47

    In case you're using vim, you can change that by setting the iskeyword option (:he iskeyword). If that is not an option, you can always use ct_ instead of counting.

    0 讨论(0)
  • 2020-12-04 23:51

    To delete to the next underscore enter "df_" To change to the next underscore enter "cf_" NOTE: don't include the double quotes.

    0 讨论(0)
  • 2020-12-04 23:55

    Is there a way to add underscore _ as well?

    :set iskeyword-=_ 
    
    0 讨论(0)
  • 2020-12-04 23:58

    You could type cf_dest_ and save the counting part.

    Edit: or as suggested: ct_ changes text until right before the underline character. (I'm using the f motion more, so it came more naturally to me)

    Or you could redefine 'iskeyword' (:help iskeyword for details).

    0 讨论(0)
  • 2020-12-05 00:02

    One other good option in such cases is to use camelcasemotion plugin.

    It adds new motions ,b, ,e, and ,w, which work analogously with b, e, and w, except that they recognize CamelCase and snake_case words. With it you can use

    c,edest
    

    and this will replace "src_branch" with "dest_branch" if your cursor was on first character of "src_branch".

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