1

I have the following mapping in my ~/.vimrc file:

 map <F3> my0v$"+y`y

It works correctly, but I'd like some visual feedback or some other indication to show that I've pressed the key. Any suggestions?

  • 1
    No answer, but isn't that the same as map <F3> "+yy? – Ralf Jan 14 at 16:08
  • This will copy the line character-wise instead of linewise. However, it will also copy the newline so it feels more linewise. I agree that it would probably be easier to just do yy/Y or :yank and just accept to do a little cleanup on paste/put. – Peter Rincker Jan 14 at 17:17
5

You have options:

  • Explicitly put an :echo at the end of your mapping. map <key> foo:echo "done"<cr>
  • Use 'showcmd' which will show partial commands. This will give you a slight clue that something happened for multi-key mappings/commands. (Not really helpful here)
  • Use a plugin like vim-highlightedyank to quickly highlight the last yank

General rule of thumbs for mappings:

  • Supply a mode for mappings. e.g. nmap for normal mode
  • Use *noremap variants unless you want remapping to occur or using a <Plug> mapping

This means your mapping would look like:

nnoremap <F3> my0v$"+y`y

Some more thoughts:

  • This is very similar to "+yy/"+Y, :yank +, or V"+y. There is another newline in the register, but that is easy to reason about.
  • You may not want the ending newline at all, so use g_ instead of $.
  • This mutates the y mark. This could be surprising, consider using a :yank or yy/Y
  • Could "cast" put/paste or change the register type to accomplish the same effect. e.g. nnoremap <f3> "+yy:call setreg('+', @+, 'v')<cr>

Personally, I lean toward using vim-highlightyank and the following mapping:

nnoremap <silent> <f3> "+yy:call setreg('+', @+, 'v')<cr>

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.