Is there any way to yank a linewise visual selection without the newline at the end of the last line of the selection? More specifically, I'd like to be able to copy a line or lines from vim to the system clipboard and paste it elsewhere without the last command being executed without a chance to edit it.
I can get the desired effect by executing this command on the register in question after yanking:
:let @*=substitute(@*,'\n$','','g')
but is there any way to execute that command automatically? I am using MacVim at the moment and there doesn't appear to be a way to map an extra command to ⌘-C, so I'd have to have another mapping to remember to execute after copying if I can't find another solution.
My original answer to myself has been working well enough that I pretty much forgot about it, but now I've decided to set clipboard=unnamed
to always yank to the system clipboard. A side effect is that yanking to the clipboard also affects the unnamed register, from which I don't want the trailing newline to be removed.
The new (and more Vim-ish) answer is a mapping to convert the linewise visual selection to characterwise before yanking it:
vnoremap <C-c> <Esc>'<0v'>g_y
Now I copy with <C-c>
if I intend to paste in a command line or just y
any other time. Pretty much what user Explosion Pills suggested but some added stuff to include the first character of the first line and last of the last line.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With