0

Example line: ^ some_string : other_string $.

How to yank some_string before : without the spaces|tabs?

  • With your cursor on the first character of the line (i.e. the first s in some_string) you want to do yf: to yank until :? – statox Jan 25 '18 at 10:00
  • Cursor can be any place in the current line. Tried yf:, it will also yank the spaces between the string and :. Seems yiw can do the job. – Fisher Jan 25 '18 at 10:08
  • Oh I didn't understand what you meant. Yes definitely yiw is what you are looking for you can see more text objects there :h object-select – statox Jan 25 '18 at 10:13
0

As you probably know all commands are quite location dependent. So the best command will differ depending on your starting location.

yiw will work fine if you are standing on the some_string. If you are on the line you can get there by ^ (go to beginning first word of the line) Then yiw to yank the word only. (thanks @statox)

  • Welcome to our site @jaan! If I may add my two cents: 0w can be replaced by ^ (:h ^). Also yiw will yank the current word while yw will yank the current word and the whitespaces until the next character which is OP was asking not to do :) – statox Jan 25 '18 at 12:51
  • Thank you. and you are very correct! i guess I was a little quick on the trigger. Should have tested before posting. I thought ^ and 0 did the same thing, good to know. And here i thought I had a pretty good understanding of vim! – jaan Jan 25 '18 at 12:58
  • That's the amazing part about Vim: you never know it all ;) You can edit your answer with the "edit" button to remove the part about yw to avoid confusion for future users. – statox Jan 25 '18 at 13:01

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.