Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

If I have this text in vim, and my cursor is at the first character:

www.foo.com

I know that I can do:

  • cw to change up to the first period, because a word (lowercase w) ends at any punctuation OR white space
  • cW to change the whole address, because a Word (uppercase w) ends only at whitespace

Now, what if I have this:

stupid_method_name

and want to change it to this?

awesome_method_name

Both cw and cW change the whole thing, but I just want to change the fragment before the underscore.

My fallback technique is c/_, meaning 'change until you hit the next underscore in a search,' but for me, that also causes all underscores to be highlighted as search terms, which is slightly annoying.

Is there a specifier like w or W that doesn't include underscores?

share|improve this question
    
What's wrong with :nohl? –  Ignacio Vazquez-Abrams Feb 10 '11 at 14:27
    
I do want search terms to be highlighted most of the time; just not when I use search as a movement. (I also just asked this question: superuser.com/questions/244042/…) –  Nathan Long Feb 10 '11 at 14:36

2 Answers 2

up vote 34 down vote accepted

You can do cf_. f won't highlight the searched character.

You can also do ct_ if you don't want to include the _.

share|improve this answer
9  
You're confusing f, t, F and T. f moves forward to the character; F moves backward to the character; t moves forward to just before the character; and T moves backward to the character to the right of the target character. So your second example should have been ct_. –  garyjohn Feb 10 '11 at 16:55
    
Now my answer is corrected. Sorry and thank you. –  doubleface Feb 10 '11 at 17:12
    
ct_ is exactly what I wanted. This has now become part of my regular workflow. Thanks! –  Nathan Long Mar 2 '11 at 11:59

Put this in your .vimrc:

set iskeyword-=_

Then _ will be treated as a word boundary (though not a WORD boundary), and cw could be used to just change "awesome", and cW to change the whole thing.

See:

:help iskeyword

and

:help word

for more info.

share|improve this answer
2  
That is fantastic! Thank you! –  Nathan Long Feb 11 '11 at 12:41
2  
It's great to know that I can define my own word boundaries, but after some thought, I think the best solution is ct_ as doubleface says below, since it's concise and is default vim behavior. –  Nathan Long Mar 2 '11 at 12:01

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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