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?
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.
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.
Simple. First copy the content and then:
pbpaste > /path/to/newfile
Related
I've started using Neovim on Windows/WSL through ConEmu. It all works pretty amazingly except one pretty major flaw:
When I paste content into Neovim and forget to enter insert mode before, Neovim will register the input as keyboard strokes and execute them as commands. Needlessly to say, this can get pretty ugly, pretty fast.
A contrived example for clarity: I need to copy some text from my browser. The text in question is "sp" (yes, this is completely stupid, but bear with me). As I paste this into ConEmu (CTRL-V), the terminal transfers the input to Neovim that parses it as commands because it's in normal mode. In this example Neovim will replace whatever character is at the cursor at the time with p.
Vim for Windows has this solved and will paste the content without changing mode (how does a pure Linux environment handle this?). The problem with that solution is that it is dependent on the Windows file system which is a lot harder to tweak/maintain compared to apt-get/Ubuntu/WSL as well other annoyances.
So, initially I thought I'd try to make Neovim detect if the input was directly from the keyboard and not any other source, if it was, switch to insert mode and handle it from there. But I'm frankly not sure if this is even possible (especially though WSL). I also tried to add a shortcut that makes Neovim enter insert mode on CTRL-V in the hopes that is would trigger first and then correctly paste the content.
Maybe I need another terminal than ConEmu?
Anyway, I'm out of ideas, hope you guys can help.
ConEmu shall not detect any "internal" modes of the application you run in the terminal. Actually, when you "paste" something, terminal does almost the same thing if you press same keys manually.
Well, except one major difference: ConEmu uses "bracketed paste mode", so the console application may determine if user paste something or press keys manually.
So, it's the question to Neovim how to process/configure bracketed paste mode inside it.
In ConEmu settings, Keys & Marco -> Paste
There is an option:
Multi-line paste: avoid unexpected command execution by < Enter >
keypress
That's what you need.
Is there "keyboard-only" way to select an entire vim document in a way that is equivalent to a left-click and drag with a mouse in normal mode? Please do not confuse this with selecting all text in visual mode (ggVG). I want to be able to follow this up with a right-click paste into notepad++ (ggVG/ggVGy followed by a right-click paste in notepad++ does not copy the document). Thanks
Again, the "ggVG" commands are not working, nor are the "+y" commands (which I should have mentioned in my original post). Perhaps it is worth noting that I am working on a Windows local machine (where I have notepad++ open) and am generating the vim file on a linux virtual machine (slurm cluster). Under these working conditions, if I left-click drag over the vim doc and right-click paste in notepad++, the selected text copies over. However, the process is cumbersome for large files, hence my inquiry. Thanks again.
You should have mentioned that, of course, as it is not a meaningless detail at all.
Manual selection in a terminal can only select the text currently displayed in the viewport, which is obviously cumbersome for larger files. The only practical way to copy on the remote machine and paste on the local machine (and vice-versa) is to enable X-forwarding and build Vim on the remote machine against X libraries. This will give you what you want: a shared clipboard.
You won't be able to reach your goal in a practical way if you can't or don't want to install the necessary stuff on the remote machine.
As a lightweight alternative, you could simply scp the remote file to your local machine.
Just use (esc) :%y+. This will copy the entire document to your clipboard. Then you can go to notepad++, or whatever else you want to use, and paste it with a right click.
Explanation:
%: Tells vim the next command will be applied to all lines.
y: to all 'yank' lines
+: Copies all lines to clipboard, You can also use Ctrl + C instead. Note: + is sometimes bound as *. And sometimes both are equivalent.
Or you can also use the slightly longer way: ggVG+.
If you really want to be fancy you can remap Ctrl + A to ggVG or %y by adding this line to your .vimrc:
map <C-a> <esc>ggVG<CR>
Try to use Xshell remote login software. in there is a option called "To Text Editor".
Just open the file using "vi filename.c" it will displayed on the screen after that just made a left click on the work area and choose "To Text Editor--->all" . then these all text moved to a notepad file then u can simply copy and paste in notepad++.
I want to select all the text from the vim editor, I tried the command :%y+ but getting error E850: Invalid register name. I get this command from this link. Please help me how to copy all the text from file which is open in vim. They are using yank, what is meaning of it..
I had a similar problem. Don't know why you got so many down votes.
The problem is that you haven't installed vim-gnome which takes about 24 MB and adds a feature to the inbuilt vim.
sudo apt-get install vim-gnome
then your command will work. :%y+ This command will copy all the text in system's clipboard.
TLDR: If you want to copy text in Vim to the system clipboard type ggVG"*y. Explanation below...
Vim runs in the terminal and, depending upon how you are using it and which type of Vim you are running, it's not really designed for you to select text with a mouse and copy and paste in the traditional way.
If you want to select all of the text using Vim then use ggVGy (note the uppercase VG in the middle). This command moves the cursor to the top of the file, enters visual mode, moves to the bottom of the file (thus, selecting all of the text) and then yanks (copies) it. You can then use p to put (paste) this code but only inside of Vim.
If you want to copy to the clipboard to use somewhere outside of Vim then try this:
First, select everything using the commands outlined above but without the final y: (ggVG). Then press "*y. This should now copy it to your operating system's clipboard and you can just paste (Ctrl/Cmd+v) anywhere you want outside of Vim. This can vary depending on what settings you have for Vim but it should work.
A brief explanation of the commands used. gg goes to the top of the file. V enters visual mode by lines. G goes to the end of the file. y yanks (copies) the text but not to the clipboard. p puts (pastes) the text.
The more advanced (i.e. cool) stuff:
" allows you to access registers. For example "a provides access to register a.
The * is the system clipboard so "* provides access to the system keyboard. Therefore, "*y yanks into the system clipboard.
While there's a great explanation of how to exploit the system clipboard in vim, it sounds like you're just having trouble getting your vim to access the clipboard in the first place. Try installing vim-gnome, it gives you the packages you need to get to the system clipboard.
For some reason, "* didn't work for me, but the exact same command with the "+ register did.
To select the whole file you can jump to the beginning, start visual mode, jump to the end:
ggVG
This question is a few years old now, but I had this same problem on Linux Mint 18. I found using xclip worked for me. You can map the command vmap <F7> :!xclip -sel c<CR><CR> in your .vimrc to have your current selection in visual mode copied to the system clipboard.
Here is a thread containing the above (and other) solutions.
You can use
Vggy/vggy or,
VGy/VGy
To visually select any number of text and then copy it, in your case it is gg / G as you want all text on the file,
gg is to copy while your cursor is at bottom of the file, gg for go to top
G is to copy while your cursor is at top of the file
Or even you can always use
Vk(as number of time)y to copy the selected lines of text.
I had rather a lot of text on my clipboard whenever I accidentally right clicked inside Putty (with Vim open), and Vim has initiated a paste operation which has been going for around ten minutes now.
I don't want to lose my unsaved work, is there a way to instruct Vim to stop pasting text?
If you're in normal mode, Ctrl-C aborts the current command in progress. Then press u to undo anything that changed before you stopped it.
Depending os your vim configuration, there's chances that you have a swap file (backup) in .nameOfTheOpenedFile.swp (substitute nameOfTheOpenedFile with the name for your file).
To recover the file :
vim -r .nameOfTheOpenedFile.swp
I know this is really old but the top answer is not right and I was clearly having a similar issue to OP. (accidentally pasted like a million lines of json into vim)
Keep in mind this may not allow you to save your work (but you can probably salvage something from the .swp file)
All you need to do is open a new terminal window and enter pkill vim into the command line.
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.
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.
:read !pbpaste
If you are using Linux use:
xsel --clipboard --output
or:
xclip -selection clipboard -o
instead of pbpaste.
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 -
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=§
did you try paste mode? set paste / set nopaste?
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
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).
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.
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...