Setting word delimiters in vi

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

Is there a way to add an underscore _ ?

I often want to change the part of a variable name containing underscores, for example, changing src_branch to dest_branch . I am finishing character counting and using s (e.g. 3sdest ), but it would be much easier to use cw (e.g. cwdest ).

+44
editor vi
Oct 22 '08 at 11:06
source share
5 answers

If you use vim, you can change this by setting the iskeyword ( :he iskeyword ) :he iskeyword . If this is not an option, you can always use ct_ instead of counting.

+17
Oct 22 '08 at 11:31
source share

Is there a way to add an underscore _ ?

 :set iskeyword-=_ 
+32
Jun 23 '09 at 18:13
source share

Another good option in such cases is to use the camelcasemotion plugin.

It adds new movements ,b ,e and ,w , which work similarly to b , e and w , except that they recognize the words CamelCase and snake_case. With it, you can use

 c,edest 

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

+4
May 14 '12 at 18:56
source share

You can enter cf_dest_ and save the counting part.

Edit: or as suggested: ct_ changes the text before clicking the underscore. (I use the f movement more, so for me it has become more natural)

Or you can override 'iskeyword' ( :help iskeyword for details).

+1
Oct 22 '08 at 11:27
source share

I just looked at it myself and added this to my .vimrc:

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

My .vimrc had problems with ^ | and ^ ", which was part of the defaultkeykey for my installation, so I changed their ascii values ​​and it works fine. My main modification was to add" ^ _ "to the end of the default setting so that vim would not see the underscore as part of the word.

0
Apr 08 '09 at 13:11
source share



All Articles