Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Faster way to paste data into vim than with paste mode?

Tags:

vim

copy-paste

When I try to paste hundreds of lines or more into Vim, even in paste mode, it takes much longer (10 times or more?) than to paste that same text into TextEdit and save it as a file. I would speculate that Vim is trying to insert one character at a time and that this is slowing things down. When it's quite a large paste, I end up having to save the text with TextEdit and then open it up in Vim. Is there a faster way to paste text in?

like image 785
meisel Avatar asked Oct 24 '25 04:10

meisel


2 Answers

If your Vim is compiled with clipboard support (:echo has('clipboard') returns 1) you can simply use "+p or "*p.

If it's not (:echo has('clipboard') returns 0), get yourself a proper Vim. On Mac OS X, MacVim is the way to go.

like image 180
romainl Avatar answered Oct 26 '25 00:10

romainl


I would speculate that Vim is trying to insert one character at a time and that this is slowing things down.

This is correct. Given how terminal works, it can't go any other way. Use GVim/MacVim in GUI mode, and the problem should go away.

Alternately, you can use terminal commands to speed things up. For example, on a Mac, you can do

:r!pbpaste

to paste whatever is in your clipboard below the current line. Vim is getting its input from the pbpaste command, not the terminal, so it avoids the terminal's one-character-at-a-time thing. If you're on Linux, see What's like OSX's pbcopy for Linux.

Another avenue of approach is to see where the hundreds of lines are coming from. If it's from another file, load it into a Vim buffer, then use Vim's native copy-paste (y, p). If it's an output from a command, consider redirecting the command's output to a file first. If it's a webpage, curl it. Clipboard and copy-paste don't really figure into the original terminal-based workflow; pipes and files do.

like image 29
Amadan Avatar answered Oct 26 '25 00:10

Amadan