Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

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:


and want to change it to this?


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:…) – Nathan Long Feb 10 '11 at 14:36
up vote 53 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
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.


:help iskeyword


:help word

for more info.

share|improve this answer
That is fantastic! Thank you! – Nathan Long Feb 11 '11 at 12:41
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
This is my personal favorite – Wade Feb 26 at 19:17

camelcasemotion is a pretty handy vim plugin that allows you to move through words when using underscore or camelcase notation. Using this plugin you can place a comma in front of many of the traditional vim motion commands which will allow you to treat words in underscore or camelcase notation as full words.

share|improve this answer

Your Answer


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.