PuTTY how to select text and copy text using keyboard ONLY

78

20

Is there any way of selecting a text with keyboard the way I do it normally using Shift+arrows.

l245c4l

Posted 2009-12-20T18:25:30.040

Reputation:

I don’t understand.  Shift and arrows are on the keyboard. – Scott – 2017-11-22T00:53:15.450

I think it is impossible. :( – Lucas Jones – 2009-12-20T18:28:50.640

Answers

74

From the PuTTY manual:

PuTTY's copy and paste works entirely with the mouse. In order to copy text to the clipboard, you just click the left mouse button in the terminal window, and drag to select text. When you let go of the button, the text is automatically copied to the clipboard. You do not need to press Ctrl-C or Ctrl-Ins; in fact, if you do press Ctrl-C, PuTTY will send a Ctrl-C character down your session to the server where it will probably cause a process to be interrupted.

Asaph

Posted 2009-12-20T18:25:30.040

Reputation: 983

9My line is 24k characters long. How can I copy it over? I can only see the last part of the line or the first part on the screen buffer. – Gaʀʀʏ – 2014-09-08T19:30:57.327

@Gaʀʀʏ I know you've long moved on from this comment, but I'd just like to note that if I have a 24k line to copy, I think the 'Copy All to Clipboard' option is justified. It's certainly what I'd call an edge case. – Sean Allred – 2016-05-03T14:07:15.200

@Gaʀʀʏ, to add to Sean's reply, the copy is from the terminal buffer and not from stdout. For very long lines it certainly is possible that the line overflowed the buffer itself. – ysap – 2016-12-08T09:43:45.207

3Shift + Insert. – phocks – 2017-03-15T06:44:21.010

26

so far as I know, there is no means of copying a selected area from the putty window to the Windows clipboard without using the mouse. there is a feature request on the putty site specifically for this functionality.

http://www.chiark.greenend.org.uk/~sgtatham/putty/wishlist/keyboard-copy.html

the only way to copy information from the putty window to the Windows clipboard with a keyboard shortcut is to use the app system menu "copy all to clipboard" (which you can invoke from alt-space, provided you set the "Window > Behavior > System menu appears on ALT-Space" option configured in putty.

Pasting from the Windows clipboard into putty can be done with Shift-Insert.

If you need to copy and paste only within the terminal window itself, refer to either the man page for the shell you're using or consider using the unix "screen" app ('man screen' for more info), which allows text selection for copy / paste within the terminal window (similar to how vi's copy / paste works). an excerpt from the man pages:

   C-a esc     (copy)        Enter copy/scrollback mode.

   C-a ]       (paste .)     Write the contents of the paste buffer to the
                             stdin queue of the current window.

   C-a {
   C-a }       (history)     Copy and paste a previous (command) line.

   C-a >       (writebuf)    Write paste buffer to a file.

   C-a <       (readbuf)     Reads the screen-exchange file into the paste
                             buffer.

   C-a =       (removebuf)   Removes the file used by C-a < and C-a >.

ives

Posted 2009-12-20T18:25:30.040

Reputation: 479

1@xgMz - Works fine for me. Surprising that that ticket was filed over 13 years ago and nobody has bothered doing it yet. – ArtOfWarfare – 2016-07-04T02:12:41.380

Link works now. – xgMz – 2016-07-25T22:28:01.643

25

control+insert = copy

shift+insert = paste

vi_dude

Posted 2009-12-20T18:25:30.040

Reputation: 277

2I don't know why this was downvoted. It's the only answer that worked for me. I was able to make an AutoHotkey script that copies text from GVim in Windows, pastes it to Putty, and runs it in an interactive IPython session – rsoren – 2014-12-18T18:18:30.433

2control+insert seems to do absolutely nothing. shift+insert does paste, though. – ArtOfWarfare – 2016-07-04T02:09:39.070

3As of 2016, it works with Windows 7 and Putty 0.63. However, the question apparently includes setting the selection for copying as well AFAICT. – stefanct – 2016-09-16T13:49:20.547

3@rsoren - the OP requests a keyboard only method. This answer requires marking with the mouse first. According to selected answer, once marked, the <Ctrl+Ins> is implied. – ysap – 2016-12-08T09:47:25.097

Does not work for me on Windows 7 – SherylHohman – 2017-07-29T19:58:23.407

It works ! Using PuTTY on windows 8. – Matteo Conta – 2018-02-02T11:36:23.990

3

To work around this problem, run PuTTY in a Windows console replacement such as ConEmu or SuperPutty.

Michael Hampton

Posted 2009-12-20T18:25:30.040

Reputation: 11 744

@sathya how does this work? what does superputty have over putty? – alpha_989 – 2017-07-24T13:42:02.960

@Michael-Hampton.. does ConEmu allow you to paste from the Windows Clipboard to the Windows Terminal with keyboard only? – alpha_989 – 2018-06-02T19:00:21.430

1How do you do this in SuperPutty? – grokster – 2014-01-15T01:35:44.443

2

This may be more of a workaround than a solution.

Within vim, if you want to copy a block that you selected in visual mode (usually a block that spans many pages), you can write it to a file (by typing :w filename.txt while the text is selected and while you're still in visual mode). Once you've done that, you can:

  1. Open the file in a Windows editor if it's mounted over Samba
  2. Read the file contents via Apache or an FTP server
  3. Email the file as an attachment (see command below -- requires Mutt):

    echo "My Message Body" | mutt -s "my subject line" -a filename.txt -- recipient@email-server.com
    

Personally I prefer option 1.

Homer6

Posted 2009-12-20T18:25:30.040

Reputation: 458

2

I use GNU screen,

I also have this in my screenrc to play nicely with vim:

register [ "\033:se paste\015a"
register ] "\033:se nopaste\015a\033"
bind ^] paste [.]

A friend of mine has a hook in screen to copy the "screen clipboard" to one or both of the x clipboards (selection or clipboard) and I believe putty does the needed translations. I'll try to dig it up.

You can probably arrange the same thing with xclip, the incantation you're looking for should be using xclip -selection clipboard

I'd test quickly to see if xclip -selection clipboard -o spits out the contents of your clipboard.

richo

Posted 2009-12-20T18:25:30.040

Reputation: 359

I wish this worked in PuTTY! I tried. It complained about "can't open display" – Brian Peterson – 2017-08-08T00:36:21.083

Using xclip should work. I use tmux and xsel to copy from Puty using keyboards.. I have yet to figure out how to paste into the Windows terminal with the keyboard – alpha_989 – 2018-06-02T18:57:11.423

2

Another somewhat makeshift suggestion is to activate Mouse Keys within Windows. In Windows 7 it's under the Ease of Access Center.

  1. Click "Make the mouse easier to use".
  2. Check on the checkbox that says "Turn on Mouse Keys".
  3. Click on "Set up Mouse Keys" for additional settings.

The default Mouse Keys hotkey is Alt + Shift + NumLock.

Hopefully hitting this key combination won't interfere with your session (or just Alt + Tab out and activate it from outside putty). I believe hitting 0 on the numpad starts a click lock, allowing you to drag over the portion of text you want to highlight/copy.

White Phoenix

Posted 2009-12-20T18:25:30.040

Reputation: 1 271

2

I was tired of scrolling down line by line via mouse left button to copy session output. But now, i need to click on middle button twice; first at the beginning and second at the end. How I did :

  1. Go to Putty Configuration window
  2. Choose "Selection" from category on the left of the window.
  3. Under 'Control use of mouse', choose 'Compromise (Middle extends, Right pastes)' if not already chosen.

sedat

Posted 2009-12-20T18:25:30.040

Reputation: 29

2Please read and make yourself understand the question and then try to answer it. – Renju Chandran chingath – 2014-10-30T11:34:40.580

This is the best way to select, and Putty takes care of the copying. To copy more than one screen of text, though, I think you pretty much need to use cat instead. vi keeps moving the cursor. – Noumenon – 2016-10-22T22:55:51.293

1

Worked on this for a while, and Putty itself can't let you copy with just the clipboard.

However, Putty can facilitate the reverse transmission of data from the remote side. If you're using a tool like Vim or Tmux to make keyboard based text selections, you can dump the output to a file, and (dating myself here) netcat to a putty reverse port tunnel to a local service which dumps input to the local clipboard.

I made a video of how to do this here: https://www.youtube.com/watch?v=RI79eeCuyvE , but here's the short version:

Set your putty > connection > SSH > tunnels to forward R11311 to localhost:1234 Use netcat as a listening server that pipes output to the windows 10 clip command which sends input to the windows clipboard. Wrap this in an eternal for loop like so:

for /L %N IN () do nc -lp 1234 | clip

Run the above in a command prompt you run as admin, because you're biding to a port.

On the remote *nix server, you need to use vim or Tmux to send text selections to a file.

Use a command to send your text selection to a file

tmux save-buffer ~/.clipboard

Or, you can use Vim to save a buffer (in this case, z) to a file

silent! redir! > ~/.clipboard
silent! echo @z
silent! redir END

I integrate the vim and tmux clipboards using the .clipboard file as an intermediary using a vim function gist.

Once your text selection is in the file, you can pipe the output to the remote side of the port forward:

cat ~/.clipboard | nc 127.0.0.1 11311

Or inside a vim script

silent! !cat ~/.clipboard | nc 127.0.0.1 11311 &

Note that the ampersand is necessary because I couldn't get netcat's -q 0 flag to work properly. Maybe you can. Without it working, it waits a full second before closing, which can break the flow of your work. With the ampersand it abandons the process instantly, which completes in 1 second in the background.

Doing all the above will fully integrate Tmux, Vim, and local putty client clipboards without touching a mouse! This was the only way I could find to do this.

Troy Fletcher

Posted 2009-12-20T18:25:30.040

Reputation: 11

Also, if you use this for multiline pastes between OS's, remember to convert between DOS/Unix line endings – Troy Fletcher – 2018-02-21T14:03:13.223

-1

If you are on windows machine it will work fine but if in case linux based machine it sometime won't work. To make it work just copy the content on any text editor and just use Shift + Insert key at line where you want to paste that.

Hope this would help!

nikhil bangar

Posted 2009-12-20T18:25:30.040

Reputation: 1