0

I have the following mapping set in vimrc that saves the file and copy its content to clipboard:

:map <F3> :w<CR>gg<S-V>G"*y

It does what I want, except when I have the cursor positioned at the last character of the buffer. Why is this?

6
  • 5
    I would just use :nnoremap <f4> :%y+ Aug 9, 2021 at 19:27
  • 1
    Does it help if you write ggVG instead of <S-V>? Not sure why it would matter, but generally no reason to do the <S- version.
    – D. Ben Knoble
    Aug 9, 2021 at 21:38
  • @ChristianBrabandt. Elegant, thanks. Aug 9, 2021 at 22:25
  • @D.BenKnoble. Without the <S- it worked. I can see no reason to use it either. I must have meant to "capitalize" V by mistake. Aug 9, 2021 at 22:29
  • 1
    @statox indeed, thank you for the reminder
    – D. Ben Knoble
    Aug 13, 2021 at 13:14

1 Answer 1

3

To fix the mapping, use V instead of <S-V>.

But as Christian points out in the comments, a simpler version exists:

nnoremap <f4> :write | %yank +<cr>

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.