tags:

views:

614

answers:

4

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

Is there a way to add underscore as well ?

I quite often want to change part of a variable name containing underscores e.g. change src_branch to dest_branch

I end up counting characters and using s (e.g. 3sdest) whereas it would be much easier to use cw (e.g. cwdest)

+1  A: 

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).

HS
+4  A: 

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.

WMR
Just vi, not vim. Wasn't aware of ct - that will certainly be a help, thanks
Joe Watkins
A: 

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.

kbosak
FYI, removing the underscore from iskeyword can mess up syntax highlighting. If anyone knows how to get vim to see the underscore as a non-word character for navigation purposes but not for syntax highlighting, let me know.
kbosak
A: 

Is there a way to add underscore as well ?

:set iskeyword-=_

Noah