1

I am writing a macro a part of which is supposed to extract verse numbers from a string such as 11.1, standing for "verse one in canto eleven". I search /11\.\zs. The cursor now is in the right place. Now if I have a one-digit verse number, I'd just select it by v, then yank it y. Fine. But that works only for the first nine verses of each canto, normally it the number I need to yank will be two digits, sometimes three digits long. Also fine, ve, BUT, then it doesn't work with one-digit verse numbers, as that will go to the end of the NEXT WORD, producing a very different effect from what I had in mind. How would I catch both the cases with the same key-stroke sequence?

Probably I'd just include the dot into the to-be-yanked word, and then later get rid of it, as that seems to work, or is there a more elegant way of doing the same thing?

  • 1
    Using simply yw or yiw (not in Visual mode) works. Also viw (to select "inside word") followed by y will work too. – filbranden Jun 4 at 17:11
  • 1
    @filbranden yw will include the space after the word, but yiw seems to be doing what is needed. – muk.li Jun 4 at 17:18
4

You can use the iw text object to select the current word only.

From :help iw:

iw: "inner word", select [count] words (see word). White space between words is counted too. When used in Visual linewise mode iw switches to Visual characterwise mode.

White space counts between words, but only when more than one word is selected.

You can either use it in Visual mode, by using viw followed by y, or just directly as a text object with yiw.

| improve this answer | |

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.