Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to solve this copy-paste issue?

Tags:

vim

Let's say you're browsing this page and you see the following snippet of code:

_trackEvent(category, action, opt_label, opt_value, opt_noninteraction)

You double-click to select the whole line, copy it and then want to insert it between the double quotes here in Vim:

<div onClick=""></div>

Well, instead of this:

<div onClick="_trackEvent(category, action, opt_label, opt_value, opt_noninteraction)"></div>

This is what I get when I do it:

_trackEvent(category, action, opt_label, opt_value, opt_noninteraction)
<div onClick=""></div>

And it's pretty annoying. It's due to the ending line break that's inserted by OS X in the clipboard. How could I tell Vim to ignore the ending line breaks when working with one liners?


1 Answers

Because you've copied an entire line (with a trailing newline), Vim uses linewise paste, i.e. the text isn't inserted at the cursor position, but in a separate line above / below the current one. With <C-R>* from insert mode, you can avoid that, but it will still insert the trailing newline.

My UnconditionalPaste plugin has a gcp mapping that pastes the register always in characterwise mode. (And several related mappings for other modes and special pastes.) With it, you just position the cursor on the first / second " and do "*gcp / "*gcP.

like image 114
Ingo Karkat Avatar answered Nov 25 '25 20:11

Ingo Karkat



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!