1

I have this wall of text open on my browser (running on MS Windows) that I need to copy and paste into vi (running in my terminal emulator, putty) in order to edit it. I tried controlC and controlV and it didn't work.

I tried looking online, but everyone said to use yy. But I don't think they understand that I'm copying text from a website on my Windows browser and trying to get it to copy into vi.

  • Instead of Ctrl-V you can try Ctrl-Shift-V while in the insert mode of vi. – Andrey Nov 10 '15 at 0:16
  • or Ctrl-Ins in the browser to copy the selected text and Shift-Ins in vi to paste (while in insert mode. if using vim with auto-indent etc, use :set paste to set paste mode before pasting). yy is for editing within vi - in vi it copies the current line to a buffer from where it can later be pasted into the document with p or P. It's no use at all for cut/copy/pasting text outside of vi. – cas Nov 10 '15 at 4:26
  • Ctrl-V, Ctrl-Shift-V, Shift-Ins: none of those suggestions are working for me on Win 7 Pro. I have not found a keyboard only solution, however clicking on icon at the upper left of the window, brings up a menu. Clicking Edit->Paste worked. – SherylHohman Jul 29 '17 at 20:06
  • To be clear, are you running Windows and connecting to a UNIX/Linux system using PuTTY/SSH? If so, VI has no way to access your Windows clipboard. But, as an alternative you can save the content to a file locally and then scp (secure copy through SSH) the file to the remote system and edit it there. – Emmanuel Rosa Jul 29 '17 at 21:35
2

With PuTTY, you can press shiftInsert as an alternative to middle-mouse pasting (and have fewer problems with inserting into the wrong place). I do this to select/paste passwords, for instance.

Here are a few related questions:

0

If you're doing this in X such as KDE or Gnome, then once you select the text it will be in your X server's "primary selection keyboard". You don't explicitly copy the text, only select. Then, make sure vi is in insert mode, place your cursor in the vi window, and click the middle mouse button.

  1. Select text in any window (which copies into the X "primary selection clipboard").
  2. Put vi into insert mode (for example, press the "i" key on your keyboard).
  3. Click the middle mouse button anywhere in the vi window to paste the contents of your "primary selection clipboard" at your vi insertion point.

You might need to adjust some features in vi, such as :set noautoindent, because if there are any spaces at the beginning of lines, autoindent will cause your pasted text to cascade to the right of the screen. There may be other settings affecting how the text is entered into the vi buffer.

  • Hi RobertL, thank you for the answer, I'm using putty as the program for the vi editor. I followed the steps exactly (selected the text in my browser, put vi in insert mode, and clicked my middle mouse button) but it still did not work, all it did was highlight the line i was hovering over in vi. I'm sorry if I'm messing up somewhere obvious, but I'm still not sure why it wont copy over. – shtr Nov 10 '15 at 0:21
  • 1
    This is Unix and Linux. If you don't say, we assume you're on a Unix/Linux system. I don't know how to do this on Windows. – RobertL Nov 10 '15 at 0:34
  • Do you get a right-click menu in the putty window? You might want to put "putty" in the title and description. – RobertL Nov 10 '15 at 0:40
  • How do I do this without a "middle mouse button", such as on a laptop's trackpad, or with a two-button mouse ? – SherylHohman Jul 29 '17 at 19:46
  • This will probably depend on your windowing system. Sometimes there's a way to access the "primary selection buffer.". If you can't do that then you can usually use the right click menu to paste into vi (when vi is in insert mode). Vi itself also has its own commands for pasting buffers. I believe that vi's named buffer with the name "*" is one of the clipboard buffers, so the vi command "*p would paste the clipboard buffer at the current insertion point. Look for "named buffers" in the vi help system. – RobertL Jul 29 '17 at 20:06
0

The root cause could also be insufficient file permissions. I encountered the issue when trying to paste text into vi from Windows and none of the suggestions above worked. Only after giving myself write permission on the file, the text could be pasted with a simple right mouse click in vi's INSERT mode.

-1

None of the keyboard-only suggestions worked with my terminal emulator on Win 7 Pro: Ctrl-V, Ctrl-Shift-V, Shift-Ins.

While I have not found a keyboard-only solution, the following worked:

  • clicking on icon at the upper left of the window, brings up a menu:
  • then click Edit->Paste
  • 1
    Since this question was flagged for deletion as "Not an answer", I've edited it so that it answers the question as asked by the OP (it was a bad question in the first place as the OP did not make it clear which terminal emulator they were using and that they were running Windows). – Anthony Geoghegan Jul 29 '17 at 21:55
  • OP made it clear in a comment. – Thomas Dickey Jul 29 '17 at 22:25
  • 1
    @ThomasDickey I saw that comment yesterday and I upvoted your own answer accordingly. However, a question shouldn't have essential information only left as a comment to one of its answers. Anyhow, I've now edited the question to make it clearer by including essential details. – Anthony Geoghegan Jul 30 '17 at 22:15

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.