2

If I type 2daW, I can delete the current Word and the next (though I can't really see that case covered in the manual).

Is there a way to visual-select around two words? I tried 2vaW, but of course (as the manual says) that does something else (something... complicated). va2W seems to ignore the count (while da2W seems to quit the action at 2 and start a new one).

1 Answer 1

4

You can of course use v2aw, v3aw and so on as described in the :h text-objects where aw is a text object that accepts count.

You can also compose viw and e. Like viwe for 2 words, viw2e for 3 words etc...

enter image description here

So what is the difference with daw, caw and vaw? Why can't you 2vaw but 2daw works?

  • d and c are operators (:h operator) -- they accept count + motion and delete or change text accordingly. So for 2daw you pass 2 for a d operator and a motion (a word text object).
  • v is a mode change -- you switch from normal to visual. Yes it also accepts a count but it does completly different thing compared to operators -- select the same number of characters/lines as used for the previous visual selection and multiply it by count. So you have selected what you didn't expect and then also made a single motion aw.
8
  • That's what I ended up doing in practice, but I though there might be a text object representing "around two words" (like a2w -- but it doesn't exist; I guess theoretically it could be defined, just like folks define the "entire buffer" text object).
    – usretc
    Mar 5, 2021 at 6:57
  • Off topic, but how do you make the animated script-like GIF?
    – usretc
    Mar 5, 2021 at 6:59
  • 1
    @AldIn there is a text object aw you can provide a count to it v10aw to select 10 "around words", d10aw to delete them.
    – Maxim Kim
    Mar 5, 2021 at 7:08
  • 1
    @AldIn screen2gif for win, there are other tools for other oses.
    – Maxim Kim
    Mar 5, 2021 at 7:09
  • Ah, it should have been v2aw, not va2w !! That's the answer I was looking for, you might want to amend your posting.
    – usretc
    Mar 5, 2021 at 7:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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