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

Consider the following line of Python:

print("\nHello, world!")

To change the word Hello to Hola one might like to simply ciw. However that naive command replaces the n of \n as well. How might one configure VIM to ignore the leading character of a word if immediately preceding the word is found the character \?

Note that VIM highlighting does recognize the leading n as belonging to the \n, so perhaps a solution could be based off of this.

share|improve this question

The word motions in Vim are universal (or "naive", as you say), and are only controlled by the 'iskeyword' setting. That's usually a good thing, because they have proved to be applicable to all sorts of text, and most programming languages.

What you want is a specialized text object; you could implement such by remapping the default iw text object (and probably also the related motions like w, e, etc. for consistency). I haven't seen any such implementation, but it's definitely doable in Vimscript. The textobj-user plugin might help.

Alternatively, you can apply the text object first on visual mode, and then correct the selection for the leading n character: viwolc. The o goes to the other side of the selection, l reduced it by once, and finally change the selection.

...or just re-type the deleted n; after all, it's just one character and quick to do. That's what I would probably do.

share|improve this answer
Thanks, Ingo. I will consider those options. – dotancohen Jul 23 '13 at 9:57

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.