4

If I have the cursor placed on "word1" and wanted to select "word1 word2 word3" (i.e. with no trailing space after "word3") what is the easiest command?

word1 word2 word3 word4

I am currently using v5iw. Is this easiest command?

1
  • 2
    Easiest is highly subjective. (It proably would mean using the mouse, as you get direct feedback on the selection, but this is very far from what typically Vim users would do.) Do you mean shortest? What makes you think you could beat 4 (unshifted) key presses? Commented Nov 20, 2018 at 12:59

3 Answers 3

2

I would go with vf3 (with the cursor at the beginning of the first word) because it doesn't require you to count anything you just have to think "I want to put my cursor in this character".

Anyway I think what you should really read is :h motion.txt to understand which motion exist and for which range they are useful.

Also asking for the best way to visually select these word might be a XY Problem: There is a good chance that what you want to do would be more efficient without a visual selection (for example df3 would deleted the words in only 3 keystrokes)

2
  • vf3 selects only the first character of the first word for me. Sure, I can use multiple ee after this, but then why not use vf0 or vf1 instead?
    – john c. j.
    Commented Aug 17, 2022 at 11:47
  • @johnc.j. f is a motion "until the next occurence of the target" and here 3 is the target. So if vf3 doesn't select until the 3 in word3 for you it might means that you have remapped f to do something else or that you have something weird in your config.
    – statox
    Commented Sep 1, 2022 at 12:13
3

For me personally, counting stuff and apply counts is not the easiest thing to do.

I prefer to do several repeats like with viwee.

Or if the ending word is quite away from the cursor position I would go with v/3/e<CR>

2

You want 3 words, and this key combination uses number 5, so not so straight-forward in my opinion. I would possition cursor on the start of word1 if needed - with b - and then used v3e (or even v3E - if the words would include for example - in them)

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.