If i type, for example, y/foo<CR> in Normal mode, i "yank" all the text until the next occurrence of "foo" without side effects. However, if i type y?foo<CR> in Normal mode, i "yank" the text alright, but unfortunately the cursor jumps to the occurrence of "foo".

Is this the expected behavior? Is there an easy workaround?

  • I overlooked the fact that all backward motions move cursor when used in Operator-pending mode. Thus the initial title of the question ("Using “search backwards” (?) in Operator-pending mode") is not particularly appropriate. I hesitate to remove the question, but i will change the title. – Alexey Mar 22 '15 at 22:27

The yank command always places the cursor at the start of the yanked text. If you use operator-pending backwards search, you basically have a reverse selection, with the jump target before the start.

As the '] mark has the end of the executed yank, you can return to that original cursor position via g`].

  • I keep learning how counter-intuitive Vim is! I didn't notice that yb also moves cursor. – Alexey Mar 22 '15 at 21:29

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.