2

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 '19 at 5:39
  • 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 '19 at 6:13
  • 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 '19 at 7:02
  • 1
    well, for "+ vim knows that the input is coming from the system clipboard while for your other method of pasting it seems vim doesn't know. So it has to process the input as typed. – Christian Brabandt May 7 '19 at 5:46
  • 1
    @Sparhawk It is not clear to me, that your terminal actually uses xterm-bracketed-paste you haven't said what terminal you used and xterm-bracketed-pasted needs terminal support. So my guess is, it is not being used (or not correctly configured), don't know – Christian Brabandt May 7 '19 at 10:13
0

You can try setting lazyredraw.

| improve this answer | |
  • Unfortunately this makes no difference. – Sparhawk Jan 28 '19 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).

| improve this answer | |
  • 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 '19 at 5:29
  • Well, have you tried the suggestion with the swapsync setting as I mentioned before? – Christian Brabandt Apr 18 '19 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 '19 at 11:50
0

What about just remap ctrl-v in insert mode to paste from system clipboard?

inoremap <c-v> <esc>"+p

Does this work for you?

| improve this answer | |
  • I'm guessing they'd also need to modify their terminal config to pass the Ctrl-V onto Vim, as in their current setup Vim won't ever see the CTRL-V keypress: it will only receive the text inserted by the terminal. – Rich Jan 13 at 15:39
  • Yes, good idea, but if the terminal never sees ctrl+v as paste, then I could never paste into the CLI, for example. – Sparhawk Jan 13 at 23:20
  • @Sparhawk, which terminal are you using? AFAIK, Linux terminal does not support ctrl-v to paste into the terminal. You need to use Shift+Insert. – jdhao Jan 14 at 2:19
  • Terminator, which does support ctrl+v for paste. shift+insert sends the primary selection instead. – Sparhawk Jan 14 at 2:20
  • Then I think you may use another terminal, for example, kitty or Alacritty. – jdhao Jan 14 at 2:25

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.