Copy from Putty/Vim visual mode to windows clipboard
Solution 1
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.
Solution 2
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
Solution 3
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.
exit from vi editor
$cat using above command you will see your all content which is in that file
select the content you want to copy (yes you can scroll on this screen while selecting)
don't click any mouse button because text will get selected automatically
open your text editor on windows and paste it there
Done
Solution 4
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
Solution 5
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
Related videos on Youtube
user886596
Updated on March 15, 2020Comments
-
user886596 about 4 years
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
-
Walf about 6 years
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. ;)
-
-
user886596 almost 11 yearsThe 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.
-
Lieven Keersmaekers almost 11 yearsI'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, 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 almost 11 yearsStrike that - Just open the system menu (top left) and select Copy All To Clipboard
-
user886596 almost 11 yearsThis 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).
-
Lieven Keersmaekers almost 11 yearsIf 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 almost 11 yearsfwiw - 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.
-
Qix - MONICA WAS MISTREATED almost 10 yearsThis 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 you will be able to comment on any post.
-
Ryan E over 9 yearsThis is the only thing so far that has worked for me
-
driftingprogrammer over 9 yearsThis 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.
-
J Bourne over 9 yearsIs there a work around for this, because I'm often using putty rather than an ssh of linux/OS X machine
-
kapad about 9 yearsI can only use this to copy what is in the box. Scrolling doesn't work. I'm using MTPutty.
-
Admin about 9 yearsIn 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: quora.com/… 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
-
Ajith about 8 yearsThis worked for me. Similarly hold down shift and right click to paste from clipboard to vim.
-
Admin about 8 yearsConfirmed as working at least in the case where the SSH host does not use X.
-
Webmaster G over 6 yearsThis 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!
-
alpha_989 almost 6 yearsThis works amazingly well. If you are on using
tmux
and you selecting something you need to usexsel
to copy it to the primary/system clipboard. -
lamanux over 5 yearsThe Brad-Denver anwser is more effective to simply copy text from vim in putty.
-
aiwl almost 3 yearsIf 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.