1

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.

1 Answer 1

3

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.

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .