24

I currently have a vim session open in Putty, and I've selected everything in the file via visual mode. Normally to copy this onto clipboard I would use either "+y or "*y, but neither of those commands are working.

Here's my vimrc:

call pathogen#infect()

set noswapfile

set mouse="

set ts=4
set wildmenu
set wildmode=list:longest,full

colorscheme evening

set expandtab
set smarttab

" Stuff from github:
set ts=4
set wildmenu
set wildmode=list:longest,full
set number

" This shows what you are typing as a command. I love this!
set showcmd

" Who doesn't like autoindent?
set autoindent

" Spaces are better than a tab character
set expandtab
set smarttab

" Who wants an 8 character tab? Not me!
set shiftwidth=3
set softtabstop=3

" Ignoring case is a fun trick
set ignorecase

" When I close a tab, remove the buffer
set hidden

" Set word wrapping
set linebreak

" Use filetype specific indentation
filetype on
filetype plugin on
filetype indent on

" Disable auto commenting
autocmd FileType * setlocal formatoptions-=c formatoptions-=r formatoptions-=o
user886596
  • 2,380
  • 5
  • 31
  • 53
  • `Spaces are better than a tab character` ... `set shiftwidth=3` If only there were some way to keep your preference for 3-space tabs and not enforce that craziness on others, some kind of semantic "tab" character, perhaps. ;) – Walf May 09 '18 at 01:17

6 Answers6

70

with mouse enabled via set mouse=a you simply need to "Hold down shift, and then highlight the text you want to copy using the left mouse button. When you release, the highlighted text should be in the Windows clipboard." See https://stackoverflow.com/a/4313348

Community
  • 1
  • 1
Brad Denver
  • 826
  • 7
  • 6
  • 1
    This is the only thing so far that has worked for me – Ryan E Aug 25 '14 at 15:26
  • 6
    I can only use this to copy what is in the box. Scrolling doesn't work. I'm using MTPutty. – kapad Feb 18 '15 at 19:56
  • 1
    This worked for me. Similarly hold down shift and right click to paste from clipboard to vim. – Ajith Feb 18 '16 at 07:12
  • Confirmed as working at least in the case where the SSH host does not use X. –  Apr 30 '16 at 11:43
  • 1
    If you hold the alt key while dragging in Putty, you can block select. Useful if you're using split screen or line numbers and it accidentally grabs those too. – aiwl Jul 02 '21 at 14:35
14

I was facing the same issue I searched everywhere but I didn't find any easy solution without installing some extra software tool. So here is the simplest solution.

  1. exit from vi editor

  2. $cat using above command you will see your all content which is in that file

  3. select the content you want to copy (yes you can scroll on this screen while selecting)

  4. don't click any mouse button because text will get selected automatically

  5. open your text editor on windows and paste it there

  6. Done

Martin Evans
  • 45,791
  • 17
  • 81
  • 97
Saurabh Dange
  • 140
  • 1
  • 5
  • 2
    This was the only logical way I could do it. It's a bit of extra work to exit file and cat, but it works for me. Thanks! – Webmaster G Aug 30 '17 at 00:40
6

When you connect to a remote system with PuTTY (using SSH I assume) and you need to transfer a complete file from that system to your local Windows one, just open a separate SCP connection; PuTTY comes with pscp.exe to transfer files. Depending on your SSH configuration, with multiplexing this may even re-use the same connection, so the overhead should be fairly small.

If you install an X Server (like Cygwin-X) and use ssh -X hostname to connect, you can launch a remote terminal / GVIM session and have clipboard synchronization with your Windows host, courtesy of the X Server. With PuTTY alone, this is not possible, since it's a sole terminal client without any connection to X.

Ingo Karkat
  • 167,457
  • 16
  • 250
  • 324
  • Is there a work around for this, because I'm often using putty rather than an ssh of linux/OS X machine – J Bourne Dec 02 '14 at 12:45
  • In the PuTTY configuration Connection -> SSH -> X11 you can enable the X11 Forwarding which will append this -X flag on connection. I can confirm this solution works, I also looked at this article: http://www.quora.com/How-can-you-copy-all-contents-of-a-text-file-opened-in-vim-through-Putty-on-a-Windows-desktop-to-Windows-clipboard I'm running PuTTY on Windows 7, connecting to a Vagrant box with the XMing port forwared and am able to copy from vim to the clipboard via `"*y` –  Apr 30 '15 at 14:07
  • This works amazingly well. If you are on using `tmux` and you selecting something you need to use `xsel` to copy it to the primary/system clipboard. – alpha_989 May 27 '18 at 16:20
  • The Brad-Denver anwser is more effective to simply copy text from vim in putty. – lamanux Sep 12 '18 at 12:06
1

I assume you expected to have the text copied to the clipboard of the host system. I doubt that's possible from within vim running in a putty session but the following works for me

  • select the text using the mouse.
  • selected text is be put in my system's clipboard.

Note that this has nothing to do with vim but is entirely putty's doing.

Edit

From Using PuTTY

3.1.3.5 Copy All to Clipboard

This system menu option provides a convenient way to copy the whole contents of the terminal screen (up to the last nonempty line) and scrollback to the clipboard in one go

Lieven Keersmaekers
  • 57,207
  • 13
  • 112
  • 146
  • The problem I have is that I need to copy an entire file (1000+ lines long) and I can't highlight everything that way. Also, I have line numbers enabled, so copying that way copies in the line numbers. – user886596 May 24 '13 at 18:45
  • 1
    I've been glossing over the putty options when opening a session but I can't find any option to synchronize clipboards. Looking at [Using PuTTY](http://the.earth.li/~sgtatham/putty/0.58/htmldoc/Chapter3.html), I'm starting to think it's not possible. Can't you ftp to the machine to get the file? Or ftp from within vim in your putty session to your local machine to put the file. – Lieven Keersmaekers May 24 '13 at 18:50
  • Strike that - Just open the system menu (top left) and select *Copy All To Clipboard* – Lieven Keersmaekers May 24 '13 at 18:53
  • 2
    This doesn't work, because it only copies what's displayed for Putty, not what's displayed in vim. It copies the entire Putty session, including all the stuff you did prior to opening vim, and copies only the section of vim that you are currently focused (so it doesn't copy all 1000+ lines). – user886596 May 24 '13 at 18:56
  • If you can display it in vim you could also cat the file in putty. It's a workaround but it would get the job done. – Lieven Keersmaekers May 24 '13 at 18:57
  • fwiw - at work, I mix and match using gvim on a windows machine and open files through ftp on unix machines or using putty to open them. I haven't settled yet on *one true way* of doing things. – Lieven Keersmaekers May 24 '13 at 19:08
1

The only reliable way to copy text/data from a remote connection I was able to find is through a third party SCP application like filezilla or winscp. You can download the last one here: http://winscp.net/eng/download.php

Nikolay Frick
  • 2,145
  • 22
  • 17
0

The easiest way I have found so far is to enable logging in my PuTTY session. Then just browse through the lines I want. Since everything on the PuTTY screen is been logged into my local file I can easily copy stuff from my local file and send it in an email or whatever.

Dharman
  • 30,962
  • 25
  • 85
  • 135
  • This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post - you can always comment on your own posts, and once you have sufficient [reputation](http://stackoverflow.com/help/whats-reputation) you will be able to [comment on any post](http://stackoverflow.com/help/privileges/comment). – Qix - MONICA WAS MISTREATED Jul 29 '14 at 05:19
  • This method is an alternative to using copy paste between putty screen and local windows host, and an alternative to using winscp to transfer text file, in order to say bring a log file to the local machine for example. – driftingprogrammer Nov 01 '14 at 23:18