Pasting large text in vim

67 views
Skip to first unread message

Ven Tadipatri

unread,
Oct 21, 2024, 2:24:36 PM10/21/24
to vim...@googlegroups.com
Hi,
I've been struggling for years with an issue of not being able to paste large amounts of text in vim in a timely manner.  Yeah, it was kind of bad, because I'd lost all hope that there would be a vim upgrade which would support a basic paste command.
  Before anyone jumps to conclusions, I did try several options - command-shift-V, entering paste mode, tried putting some sort of weird vmap command in my vimrc that called pbcopy. But nothing worked as I just stared at my screen watching text very slowly being pasted.
 Then, I discovered something that changed my vim experience and just wanted to share that with some of you. It turns out there is a star/asterisk register, which holds the clipboard contents. So you can just press double quote - shift 8 -then p (that's "*p) , and instantly, all your worries about pasting large text in vim just go away.
  Now, there is some fine print that I should let people know. Your vim compiler needs to be built with a "+clipboard" option. And of course, finding out your vim compiler options is not common knowledge. But that's easy to check too - just run "vim --version" and pipe it to grep clipboard, and you can see have this amazing feature builtin.
  Don't take my word for it - try out the star register and just watch how these 3 characters can transform your vim copy-paste experience for large clipboard contents.

Thanks,
Ven

Igbanam Ogbuluijah

unread,
Oct 22, 2024, 9:18:44 AM10/22/24
to vim...@googlegroups.com
This brings some massive increase in quality of life! Thanks for sharing this.

To take this further, you can map <leader>p to "*p and increase quality of life.

Another way to check what your vim's built with is :version from within Vim; gives proper syntax highlighting



Igbanam


--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/CAEodY64rgQZJVGid9_rz-vEb%3DmwVcx7Kw5jzrXBs9KWWCsp2mA%40mail.gmail.com.

duh

unread,
Oct 23, 2024, 12:29:00 PM10/23/24
to vim...@googlegroups.com


Igbanam


On Mon, Oct 21, 2024 at 7:24 PM Ven Tadipatri <vtadi...@gmail.com> wrote:
Hi,
I've been struggling for years with an issue of not being able to paste large amounts of text in vim in a timely manner.  Yeah, it was kind of bad, because I'd lost all hope that there would be a vim upgrade which would support a basic paste command.
  Before anyone jumps to conclusions, I did try several options - command-shift-V, entering paste mode, tried putting some sort of weird vmap command in my vimrc that called pbcopy. But nothing worked as I just stared at my screen watching text very slowly being pasted.
 Then, I discovered something that changed my vim experience and just wanted to share that with some of you. It turns out there is a star/asterisk register, which holds the clipboard contents. So you can just press double quote - shift 8 -then p (that's "*p) , and instantly, all your worries about pasting large text in vim just go away.
  Now, there is some fine print that I should let people know. Your vim compiler needs to be built with a "+clipboard" option. And of course, finding out your vim compiler options is not common knowledge. But that's easy to check too - just run "vim --version" and pipe it to grep clipboard, and you can see have this amazing feature builtin.
  Don't take my word for it - try out the star register and just watch how these 3 characters can transform your vim copy-paste experience for large clipboard contents.

Thanks,
Ven
--
--
--

This was such a pleasant surprise when I tried it that I just wanted to jump in with a "me too" jump on the bandwagon for this hint in the hopes of generating a mini-band-wagon

effect. Well done. Thanks also for the reminder about the -version option. It seems it can be done also inside vim with :version. Thanks.

Riza Dindir

unread,
Oct 23, 2024, 11:09:44 PM10/23/24
to vim...@googlegroups.com
Was using xsel with macros for that. Good to know. Thanks.

--

Enan Ajmain

unread,
Dec 26, 2024, 8:39:16 AM (10 days ago) 12/26/24
to vim...@googlegroups.com
On Mon, 21 Oct 2024 14:23:47 -0400
Ven Tadipatri <vtadi...@gmail.com> wrote:
> [...]
> Now, there is some fine print that I should let people know. Your vim
> compiler needs to be built with a "+clipboard" option.

This is the sore point. For people who use Vim over ssh, this is not an
option (ssh -X is crappy at least in my experience). OSC52 is a godsend
for this, but it only works for copying not pasting (for security
reasons). I've been dealing with it with ':set paste!' & <C-S-v>, but
as you said, for large text that's problematic.

So what I tend to do is: I send the clipboard content to a temp file
over ssh and then use remote Vim's local register to copy from that temp
file. It's a rare enough case that this doesn't bother me anymore (*he
says through gritted teeth*).

xclip -o | ssh en...@remote.org 'cat > tmp.txt' # from local shell
# then copy content from tmp.txt to real-file.txt with Vim

--
Enan

Tim Chase

unread,
Dec 26, 2024, 9:00:40 AM (10 days ago) 12/26/24
to vim...@googlegroups.com
On 2024-12-26 08:39, Enan Ajmain wrote:
> Ven Tadipatri wrote:
> > Now, there is some fine print that I should let people know. Your vim
> > compiler needs to be built with a "+clipboard" option.
>
> This is the sore point. For people who use Vim over ssh, this is not an
> option (ssh -X is crappy at least in my experience). OSC52 is a godsend
> for this, but it only works for copying not pasting (for security
> reasons). I've been dealing with it with ':set paste!' & <C-S-v>, but
> as you said, for large text that's problematic.
>
> So what I tend to do is: I send the clipboard content to a temp file
> over ssh and then use remote Vim's local register to copy from that temp
> file.

While kinda hackish, I tend to

:r !cat

then paste the contents into the terminal/ssh window (doesn't get
impacted by auto-indent) and then control+d to send the EOF when done.

> xclip -o | ssh en...@remote.org 'cat > tmp.txt' # from local shell
> # then copy content from tmp.txt to real-file.txt with Vim

It has the benefit that I don't need to clean up the temp-file when
done. Also, it works in vi/nvi on my BSD boxes that don't have vim, and
even works in ed(1) when I'm using that (though I do have to beware if
the pasted text has any lines consisting of only a period)

-tim





Enan Ajmain

unread,
Dec 26, 2024, 9:33:39 AM (10 days ago) 12/26/24
to vim...@googlegroups.com
On Thu, 26 Dec 2024 08:00:30 -0600
Tim Chase <v...@tim.thechases.com> wrote:
> While kinda hackish, I tend to
>
> :r !cat

The real issue is that pasting large amounts of text into terminal
emulator takes a long time, because (I suspect) it pastes it one
character at a time and each time the emulator redraws the screen. So
':r !cat' is the same as <C-S-v> in that regard. Or at least I think
so.

But still, ':r !cat' lets me paste stuff without the ':set paste!'x2
hassle. That's nice - thank you.

--
Enan

Gary Johnson

unread,
Dec 26, 2024, 1:29:25 PM (10 days ago) 12/26/24
to vim...@googlegroups.com
On 2024-12-26, Enan Ajmain wrote:
> On Mon, 21 Oct 2024 14:23:47 -0400
> Ven Tadipatri wrote:
> > [...]
> > Now, there is some fine print that I should let people know. Your vim
> > compiler needs to be built with a "+clipboard" option.
>
> This is the sore point. For people who use Vim over ssh, this is not an
> option (ssh -X is crappy at least in my experience).

This has not been my experience at all. I routinely copy and paste
over ssh with never a problem.

Regards,
Gary

Enan Ajmain

unread,
Dec 26, 2024, 2:07:47 PM (10 days ago) 12/26/24
to vim...@googlegroups.com
Do you use the -X switch with ssh? If not, how are you copy-pasting?
And if yes, are you using the "* or "+ register?

--
Enan

Gary Johnson

unread,
Dec 26, 2024, 3:33:43 PM (10 days ago) 12/26/24
to vim...@googlegroups.com
>ForwardX11 And if yes, are you using the "* or "+ register?

I don't use any ssh options on the command line, just the host name.

I have these set in ~/.ssh/config for every host I ssh to:

ForwardX11 = yes
ForwardX11Trusted = yes

It seems that I shouldn't need both, but I've had issues in various
work and home environments that went away when I used one or the
other and both have worked, too.

'clipboard' is set to this:

clipboard=unnamed,autoselect,exclude:cons\|linux

so I generally use the unnamed register, but when I use a name,
I use "* rather than "". That is, I yank to the default, unnamed
register and put from it as well. So, to copy an entire file, it's

ggyG

in the source buffer and

p

in the destination buffer.

I did notice some slowness today when pasting a 41,310-line file
over ssh as an experiment. Sometimes it took 12 seconds; other
times it took only 1 second. I seldom copy-and-paste that much
text, so I've not noticed any slowness before. If you do that
regularly with that kind of performance, I can see how that would be
annoying.

Regards,
Gary

Reply all
Reply to author
Forward
0 new messages