0

In vim you can do daw to delete the entire word, but it also removes the space after the word, (caw too).

Is there a way to operate on the entire word without effecting the space around it?

For example

a d c
  ^

Performing caw -> b

Gives us:

a bc

Is there a way spaces can be treated as other delimiters, brackets for eg, which would give us:
a b c ?


While this isn't what you would do as a user, it makes writing macros more difficult, since surrounding delimiters aren't as predictable.

Note, this is quite similar to this question, but not identical since the word may be surrounded by tabs or other delimiters. https://stackoverflow.com/questions/1607904/vim-deleting-from-current-position-until-a-space

3

Yes, you can use the iw object. For example, diw or ciw etc. You can read more about the various text objects available to you here.

In this particular case, rather than ciw, you could just use cw, since it happens to be equivalent to ce. This is a special case, since for example dw would delete the extra space. You can read more about this behavior here in the documentation.

  • cw doesn't operate on the whole word. ciw is what I was looking for, thanks! – ideasman42 Aug 27 '16 at 6:38
  • @ideasman42 Yes it does. Unless you are not at the start of the word. – DJMcMayhem Aug 27 '16 at 6:41
  • ... which happens more often? :) – VanLaser Aug 27 '16 at 12:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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