Given a file like this:


If I were to type the following commands: ggVj"zy, followed by :reg z, I would see Roy and Maurice.

Now I want to yank Jen and Douglas into the z register, but by a different method. If I do: GVk:normal! "zy<CR> (where <CR> is a key press of the Enter key, of course), the z register remains unchanged. Even erasing the '<,'> range modifiers after typing : doesn't help.

The above is an easy way to show the problem. I'm implementing it in a function that I call with a vnoremap key mapping:

function! Foo()
    reg z       " show before
    normal! "zy
    reg z       " show after

So why is my normal! "zy statement not working? Is there something I've missed or misunderstood?

  • Side note, you could also use :[range]yank z. If you have a range, it could be :'<,'>y z Jan 22, 2021 at 22:31

1 Answer 1


Is there something I've missed or misunderstood?

Yes, there's no y command in Normal mode. It's y{motion}.

As your command ends prematurely it simply does nothing.

  • Of course - Visual vs Normal mode. It looks like I'll have to investigate the range modifier in my function definition. I was hoping to avoid that.
    – Phil R
    Jan 22, 2021 at 19:25
  • 1
    @PhilR you can just reenter visual mode using normal! gv
    – Mass
    Jan 22, 2021 at 19:31
  • 2
    @PhilR Usually, it's easier to start Visual-mode mapping with "zy and only then call a function. But if you really must do it the other way round, you have normal! gv"zy, as @Mass suggested, or '<,'>yank z if you support only linewise selections.
    – Matt
    Jan 22, 2021 at 19:42
  • @Mass, @Matt Thanks for the suggestions. The gv command is what I need in my situation. I don't want to limit myself to linewise selections, and my function is taking the precaution of saving and restoring the contents of @z when it's done.
    – Phil R
    Jan 22, 2021 at 20:21

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.