1

Occasionally, I paste large amounts of data into vim, using Ctrl+v in my terminal emulator (in Linux). This takes several seconds before vim is responsive again. I have tried two other methods, which work well: either "*P, or temporarily :set noswapfile before pasting.

I have tested launching vanilla vim, using vim -u NONE, and the problem still persists. As a reference, this 5600-character lorem ipsum takes ~3 seconds to paste with Ctrl+v. It's almost instantaneous with "+P.

I only need the paste alternatives with large data and vim. In all other situations I use Ctrl+v. In vim, this also has the added advantage of working in insert mode. It's only after I paste long data, when I regret my life choices.

Is there a way to automatically apply some workaround, so that is it consistently quick to paste with Ctrl+v?

  • Do you set paste/use 'pastetoggle'/use umimpaired.vim’s yop before you paste? IIRC they significantly speed up pasting, and the last one is easy on muscle memory. 'pastetoggle' is useable in Insert mode though – D. Ben Knoble Jan 27 at 5:39
  • Oops, I forgot that I had this in ~/.vimrc. It seems like the current version of vim doesn't need set paste any more. I tested without it, but it's still super slow either way. Using the linked code, the terminal isn't constantly updating through the paste, but it's only a relatively minor improvement (~4 s vs. ~6 s for a 300 000 character paste), as opposed to using "*P which is almost instantaneous. – Sparhawk Jan 27 at 5:49
  • 1
    300000 chars? Personally I’d drop to a shell and do pbpaste >> file or equivalent. You might get away with :read !pbpaste but honestly I expect a performance hit with that much input` – D. Ben Knoble Jan 27 at 6:13
  • This was more for testing purposes; I do still see a long lag for even half a page worth of text. (It also appears to be non-linear. It's not like it's a .5 second pause here.) – Sparhawk Jan 27 at 6:15
  • 1
    I often paste large logs I may get through a webpage in vim so I can search through them properly (so, definitely more than half a page of text) and pasting is instantaneous (I'm on Linux). Maybe try a fresh vim (in a VM maybe, no plugins or vimrc). If pasting is fast there, then reintroduce your vimrc and plugins bit by bit till you find out which one is at fault. – Shahbaz Jan 27 at 7:02
0

You can try setting lazyredraw.

  • Unfortunately this makes no difference. – Sparhawk Jan 28 at 0:47
0

you could try disabling backup/swap files. if pasting the contents into memory is all you want, disabling disk writes might be faster.

from https://stackoverflow.com/q/743150/11374957

set nobackup       "no backup files
set nowritebackup  "only in case you don't want a backup file while editing
set noswapfile     "no swap files

you could do a comparison with/without those settings and see if it's any faster. another option: do the same test, but turn on a disk I/O monitoring app first and see if that shows any meaningful spike (with backup files enabled) vs. drop (with nobackup, nowritebackup, noswapfile).

  • It's maybe twice as faster with those three settings than without, but still considerably slower than "+p. Also, in the long term, I certainly don't want to disable those settings. Given that "+p is near instantaneous with those settings set, I feel like there is some other issue here. – Sparhawk Apr 18 at 5:29
  • Well, have you tried the suggestion with the swapsync setting as I mentioned before? – Christian Brabandt Apr 18 at 6:04
  • @ChristianBrabandt Oops, sorry, I must have missed that. I'm away from this system for a week or so, but I'll have a look when I'm back. – Sparhawk Apr 18 at 11:50

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.