Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pasting a huge amount of text into vim is slow?

Tags:

vim

Someone showed me how to do this before but I can't figure out what it was now.

I know about :set paste but this is not the problem.

like image 593
John Tomson Avatar asked Aug 15 '13 17:08

John Tomson


People also ask

Why is my Vim so slow?

First, get a feel for how fast Vim can be: run with vim -u NONE and comment out everything in your . vimrc - then do the single thing that seems slow. Run without the -u NONE and compare. It should be just as fast, or some plugin is autoloaded and is causing problems.

How do I paste properly in Vim?

That makes the default paste buffer map to X's clipboard. So, if I mark a bit of text in a terminal, I can simply press p to paste it in vim. Similarly, I can yank things in vim (e.g. YY to yank the current line into the buffer) and middle click in any window to paste it.

How do I copy a chunk of text in Vim?

For copy: Place cursor on starting of block and press md and then goto end of block and press y'd. This will select the block to paste it press p. For cut: Place cursor on starting of block and press ma and then goto end of block and press d'a.

How do I stop Vim from Pasteing?

vim Inserting text Disable auto-indent to paste code Just press F3 in insert mode, and paste. Press F3 again to exit from the paste mode.


2 Answers

Use "*p or "*P to paste from the system clipboard instantly.

Vim must be compiled with +clipboard for this to work.

See :help clipboard for more information.

like image 87
Nikita Kouevda Avatar answered Sep 21 '22 19:09

Nikita Kouevda


This is a buffer flush-to-disk problem. Vim tries to keep your work safe and doesn't assume you can type several thousand characters per second. Read :help swap-file for some details on the buffering. The solution to your problem is this:

Turn off vim's swapfile either with:

vim -n <your file> 

or from within vim before the paste:

:set noswapfile 

See :help swapfile for more details.

Another option is to simply turn off the syncing to disk of the swap file with :set swapsync= but this option takes more keystrokes to undo and I'm lazy. :)

Turning off swap is not safe for normal operations! Immediately after the paste, either use :set swapfile or :set swapsync=fsync to revert back to normal behavior (though technically, normal behavior might have been sync and not fsync, check with :set swapsync? beforehand if you want to go this route).

like image 24
linux_sa Avatar answered Sep 20 '22 19:09

linux_sa