1

Say I have a phrase is later found at and what to delete a phrase later found, then what I do would be

In the normal mode, I put a cursor on l, and press vww. This will select from l to a of at.

This is not very practical for deleting and replacing phrases. Is there a better way/way to modify this behaviour such that vw will select a word and a space after that and not the first letter of the next word?

1 Answer 1

0

Closest to your method

v2e to visually select to the end of the 2nd word. Therefore v2ec would select the two woulds and then change them (i.e. delete them and leave you in insert mode)

You can avoid visual mode altogether (saving a keystroke) and do c2w to 'change 2 words' (c2e would also work). Of course, you don't get any visual feedback, so you need to get it right first time (which isn't too hard, once you get used to it).

Or use text objects from visual mode (see :help text-objects)

Text objects are nice because you can repeat them using the dot command on other places in the text as long as the cursor is somewhere on the text object (e.g. a word, sentence, paragraph, between quotes, between parentheses...)

note the h to move back onto the end of the word...:

  • v2awhc would change the two words
  • v2awhy would yank the two words
  • v2awhd would delete the two words
  • v2awhg~ would toggle the case of the two words

note the 3i instead of the h...:

  • v3iwc would change the two words
  • v3iwy would yank the two words
  • v3iwd would delete the two words
  • v3iwg~ would toggle the case of the two words

Or use text objects from normal mode (see :help text-objects)

  • c2aw would change the two words
  • y2aw would yank the two words
  • d2aw would delete the two words
  • g~2aw would toggle the case of the two words

Since text objects are nice, and since you can see they work better straight from normal mode (compared to visual mode) I prefer to avoid visual mode most of the time (but not all the time: visual mode is just the right thing in some situations).

4
  • I think you have an extra d in the visual case-toggle mapping.
    – D. Ben Knoble
    Jan 13 at 13:13
  • There’s also the difference between (e.g.) d2aw and 2daw, mostly in how they interact with .. I find daw. easiest, but I don’t like to count
    – D. Ben Knoble
    Jan 13 at 13:14
  • 1
    @D.BenKnoble Thanks for pointing out the typo (fixed). And re the difference noticed it since I tend to just use daw + . until I've deleted all the words (I don't like counting either :) ). Anything requiring more than ~4 hits of the . will prompt me to use a different motion (f, t, /` etc.) in the first place
    – mattb
    Jan 13 at 15:24
  • 1
    Thank you I guess vee works as equally well as the answer; and thank for mentioning other useful shortcuts!
    – Tom
    Jan 14 at 15:48

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.