29

My Macbook was stuck yesterday, when I tried to paste 1200 lines of 80 characters to Vim. It was much faster to download the file, and not to paste the text.

I have thought that this problem might be the reason, why internet operators allow slower uploading than downloading.

Léo Léopold Hertz 준영
  • 134,464
  • 179
  • 445
  • 697

9 Answers9

46

If you paste it into a terminal window, Vim thinks you're typing it out by hand, and it will try and update the display as you go. You can access your clipboard (on OS X) using the pbpaste and pbcopy commands, so you can just do this in Vim:

:read !pbpaste

or in a shell:

bash$ pbpaste | vim -

If you were using GUI Vim, you would use the "* register to paste (this is what the context menu does):

"*P   <- in normal mode

Pasting into the terminal window is usually a bad idea, try and use pbpaste where you can.

too much php
  • 88,666
  • 34
  • 128
  • 138
22
:read !pbpaste

If you are using Linux use:

xsel --clipboard --output

or:

xclip -selection clipboard -o

instead of pbpaste.

datentyp
  • 1,371
  • 12
  • 9
  • 5
    This is a life saver! vim paste has been getting slower and slower over the years for some reason, to the point that it is now unbearable. To be very explicit, for Ubuntu/Kubuntu users, install using "sudo install xsel". And then in vim, type in ":r !xsel --clipboard --output" to paste the clipboard. – Michael Mikowski Jul 25 '11 at 19:57
  • THANK YOU SO MUCH. I've been looking for xsel FOREVER. – EricR Aug 16 '12 at 19:06
6

That is "normal". It's slow because redrawing the text thousands of times is slow.

As you paste the long line in, it's constantly update the display (because of how vim deals with text, or how the terminal is handing vim text, I guess).

I tried pasting the text in vim (using iTerm) and it has the same issue, it takes a while to paste. I tried :set paste and :set nowrap and still as slow. Pasting the line straight into a terminal is equally slow

With the dpaste link you mention, there is a plain-text link, which you could just wget and edit:

curl http://dpaste.com/115362/plain/ | vim -
dbr
  • 165,801
  • 69
  • 278
  • 343
3

I favor set paste/nopaste like Masi suggested. In .vimrc, you can map some character to toggle paste (if often needed).

i.e.

set pastetoggle=§
Niko Riitala
  • 179
  • 3
2

did you try paste mode? set paste / set nopaste?

ʞɔıu
  • 47,148
  • 35
  • 106
  • 149
2

if you :syntax off you can sometimes improve an in place paste of a long single line file. An example would be a machine generated xml file.

you can probably disable vim's redraw whilst pasting as well, look at :he redraw , but it's always worth using command line stuff as If you are repeating the procedure or similar you can always automate it with a script / vim macro

michael
  • 11,667
  • 2
  • 26
  • 25
1

I don't know if this is a Mac issue or something else, but I have no problems whatsoever with pasting that amount of text in Vim. I have tried on Windows and Linux, and haven't seen any problems.

I have successfully edited files of several hundred megs (log files) in Vim (loading is slow, but once the text is read everything is pretty snappy).

Brian Rasmussen
  • 114,645
  • 34
  • 221
  • 317
1

But if it's on the web, you should have tried:

:e http://link/to/file 

Then if necessary save it as a local file.

And if it's slow because of the redrawing, look at this option:

            *'lazyredraw'* *'lz'* *'nolazyredraw'* *'nolz'*
'lazyredraw' 'lz'   boolean (default off)
            global
            {not in Vi}
    When this option is set, the screen will not be redrawn while
    executing macros, registers and other commands that have not been
    typed.  Also, updating the window title is postponed.  To force an
    update use |:redraw|.

And if it's a local file, then pasting is not necessary: try

:read file 

instead.

Zsolt Botykai
  • 50,406
  • 14
  • 85
  • 110
0

If you use Apple Terminal try an other terminal, like iTerm. Sometimes, the "build-in" terminal is not really reactive for common task. Don't know why...

GiDo
  • 1,280
  • 12
  • 23