Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to copy formatted code to clipboard #3518

Closed
thomas-taylor opened this issue Feb 26, 2016 · 61 comments
Closed

Add ability to copy formatted code to clipboard #3518

thomas-taylor opened this issue Feb 26, 2016 · 61 comments
Assignees
Labels
feature-request Request for new features or functionality
Milestone

Comments

@thomas-taylor
Copy link

thomas-taylor commented Feb 26, 2016

I'd like to request adding the ability to copy selected code to the clipboard with syntax highlighting. This is useful for pasting formatted code into another application (e.g., Word document, e-mail).
Regular Visual Studio does this by default (it puts both text and RTF formats on the clipboard).
RTF works well for me, but maybe HTML would be okay too, as long as it is 'pastable' (dependency-free).

@Tyriar Tyriar added the feature-request Request for new features or functionality label Feb 27, 2016
@sushruth
Copy link

👍

@pcgeek86
Copy link

We definitely need this. I'd like to copy / paste formatted code into PowerPoint presentations.

@harikrishkk
Copy link

Thumbs up!.. Would be awesome if the code can be copy pasted along with the syntax highlighting into word or ppt!.. Such a good IDE, especially with typescript + angular 2 combo , this wud be like gold for me!...Please provide syntax highlighting..

@theramiyer
Copy link

Would love this feature! We regularly share code, and it would be much easier to read/understand if there's color coding and indentation.

@nicsu
Copy link

nicsu commented Jun 1, 2016

👍

@Tyriar
Copy link
Member

Tyriar commented Jun 1, 2016

You should be able to write an extension to do this, you would need to include a syntax highlighter in the extension though. I'm not sure we would want to integrate something like this into the core editor (concerned about feature bloat).

@andybrodie
Copy link

I would really like this feature. I was quite surprised that this wasn't already supported when I tried it (I'm a Visual Studio user!). If an extension had to do its own syntax highlighting I think that wouldn't be a great user experience, as I find how VSCode highlights absolutely fine and wouldn't want to have to manage a separate highlighter configuration.

Are you concerned about feature bloat from an end-user perspective or from the codebase itself? I wouldn't comment on the latter, but from an end-user perspective, I enjoy the fact that it's seamless on VS. i.e. VS copied the colour information and if I tried to paste in to an app that didn't support colour (e.g. notepad) then it just disappeared and the app behaved as if I was pasting plain text. In apps like PowerPoint (where I regularly copy and paste code snippets!) I have the source formatting and plain text options available.

@skywalkerlw
Copy link

+1

3 similar comments
@Xarkam
Copy link

Xarkam commented Aug 16, 2016

👍

@SirwanAfifi
Copy link

👍

@crazyquark
Copy link

👍

@sushruth
Copy link

Is there anything that is blocking this, or is it not a desired feature ?

@ryansmccoy
Copy link

Dear GitHub Gods,

Please add this feature.

Sincerely,
Ryan

@steveluc
Copy link

Would love to see this happen. Great for communicating about code.

@atian25
Copy link

atian25 commented Sep 23, 2016

there is a plugin for atom: https://atom.io/packages/copy-as-rtf

and Code highlighting for Keynote presentations

maybe someone can write a plugin to wrap these

@atian25
Copy link

atian25 commented Sep 26, 2016

HI, I had just publish a plugin for this:

@theramiyer
Copy link

Hey, thanks, Atian! We'll check it out!

@johncruise
Copy link

johncruise commented Oct 14, 2016

Hello @atian25,

Thanks for the extension but it copies the text and put "literal" RTF signatures/tags (whatever people call them) around it. So when I paste the code, I get something like this:

{\rtf1\ansi\uc0\deff0{\fonttbl{\f0\fmodern\fprq1\fcharset0 Monaco;}}{\colortbl;\red136\green136\blue136;\red186\green33\blue33;\red0\green68\blue221;\red102\green102\blue102;\red64\green128\blue128;\red160\green160\blue0;\red25\green23\blue124;\red0\green128\blue0;\red187\green102\blue136;\red187\green102\blue34;\red136\green0\blue0;\red170\green34\blue255;\red153\green153\blue153;\red0\green160\blue0;\red160\green0\blue0;\red255\green0\blue0;\red128\green0\blue128;\red176\green0\blue64;\red0\green0\blue255;\red187\green187\blue187;\red188\green122\blue0;\red0\green0\blue128;\red125\green144\blue41;\red210\green65\blue58;}\f0 \fs50{\chbrdr\chcfpat16 @}unittest.skipIf(mock is None, {\cf2 "`mock` module not installed!"})\par

... when I am expecting a color coded text similar to below:

@unittest.skipIf(mock is None, ...)

If it helps, I'm pasting it into an blank Outlook email window.

For those who want an interim solution, look at Notepad++'s NppExport plugin (Copy HTML to clipboard)

croppercapture 2

@atian25
Copy link

atian25 commented Oct 14, 2016

hey, @johncruise

the gif is truncated, can't see what menu is selected.

the extension is use pygments behind, and it offer HtmlFormatter

so, for now, you can:

  • set copy-syntax.defaults.format to html
  • maybe copy-syntax.formatters.html.full to true and other options list at HtmlFormatter
  • then copy and you will get html output

but, I don't know whether copy-paste module can copy it to clipboard with correct format (see atian25/vscode-copy-syntax#1)

I don't have window and outlook now, could you please have a try and feed back?

btw, you can report an issue/suggest at https://github.com/atian25/vscode-copy-syntax/issues

@atian25
Copy link

atian25 commented Oct 14, 2016

@Tyriar does vscode have any api for extension to set clipboard?

@Tyriar
Copy link
Member

Tyriar commented Oct 14, 2016

@atian25 there is no copy and paste in the API, I think the advice is to pull in a node module which does it for you.

@nashwaan
Copy link

nashwaan commented Jan 3, 2017

@Tyriar This capability should be part of native VS Code experience, not as a plugin.
If anyone doesn't like the colors, he can simply select the pasted code and apply a single color to them.

How many 👍 do you need before getting convinced to implement it as part of VS code?
; )

@alexdima alexdima removed their assignment Jan 21, 2017
@alexdima alexdima added this to the Backlog milestone Jan 21, 2017
@egamma egamma assigned rebornix and unassigned aeschli Feb 8, 2017
@rebornix
Copy link
Member

@harikrishkk Just simply Ctrl/Cmd+C without any configuration.

@thomas-taylor @schallm or anyone uses Dark theme, I'm a Dark theme guy as well. At the very beginning, I didn't put the background color from the theme into the output content, but later on I found for most cases the output is ugly or unreadable. I suppose you can imagine that as for Dark theme, the font color are always light. Light font above white background is terrible most of the time. The dark theme you are using makes sure that the background color and foreground color has good contrast so I choose to ship bkg color to the clipboard.

I can see reasons that why customizing the pasted content style is useful as sometimes you can't easily modify the styles in the target application. Look forward to more users feedback on this once we ship it to stable.

@schallm
Copy link

schallm commented Feb 17, 2017

Here is a screenshot of VS2015 (dark theme) with code selected, copied to clipboard, pasted to Outlook... I don't know if they use a different theme when copying, but it works great. I get syntax highlighted code that looks great, but without the dark background...

screenshot

@thomas-taylor
Copy link
Author

@harikrishkk - You say you have latest, but just to be sure you know, today this is only in the insider build: https://code.visualstudio.com/insiders

@rebornix - I think the way it matches the theme exactly (including background) is perfect. Regular VS 2015 appears to switch the entire theme (for example text that is white in VS 2015 dark theme is pasted as black text in Word/Outlook). This works fine too (for my needs), but I like your implementation in VS Code better. That said, I also like the suggestion from @schallm to have a setting to choose the theme that you want to use for this cut/paste feature.

@harikrishkk
Copy link

harikrishkk commented Feb 17, 2017 via email

@AroraMunish
Copy link

When I try to copy using right click | Copy Syntax, I get the error "Command failed: python -V". Do I need to pre-install anything?

@harikrishkk
Copy link

harikrishkk commented Feb 19, 2017 via email

@AroraMunish
Copy link

Thanks Harikrishnan .. it worked..

@MateenKadwaikar
Copy link

Not working with Powerpoint. I have to copy it in Word first then I have copy from word and paste in Powerpoint

@rebornix
Copy link
Member

@MateenKadwaikar is there anyway in Powerpoint that can trigger a force copy with formatting? In Outlook on macOS, I have to do that always as the default paste is just pasting plain text.

@Meligy
Copy link

Meligy commented Feb 21, 2017

@MateenKadwaikar , +1 to @rebornix. PowerPoint has a default text based paste. From Edit menu though you can choose "Paste Special...", which will give HTML and RTF options. I have found the VS Code HTML copy to work with both.

@harikrishkk
Copy link

harikrishkk commented Mar 14, 2017 via email

@dalyIsaac
Copy link

+1 It doesn't work with OneNote 2016 either

@rebornix
Copy link
Member

@dalyIsaac do you mind sharing what platform and version you are using and a gif can help me understand what's going on, thanks!

@atian25
Copy link

atian25 commented Apr 12, 2017

Guess:

  • maybe vscode is copy as HTML format
  • keynote only support RTF format
  • word/mail support both

untitled

@tedyun
Copy link

tedyun commented May 3, 2017

@rebornix Is this feature configurable? I couldn't find a setting for disabling this feature.. Unlike other people in this thread I personally prefer copying the plain text and nothing else. I also think copying plain text should be the DEFAULT behavior, like all other similar, non-IDE text editors (e.g. Atom, Sublime Text, Notepad++).

I appreciate all the effort went into enabling this feature. I hope you guys can add a boolean option in Settings file to enable/disable it.

@lukeaus
Copy link

lukeaus commented May 24, 2017

@tedyun If you want to copy plain text: select text the Edit --> Copy
If you want to copy with syntax: select text then open command pallate and select "Copy with Syntax Highlighting"

@tedyun
Copy link

tedyun commented May 24, 2017

@lukeaus It doesn't work that way in my machine. Both (Edit -> Copy) and (Ctrl+C) copy the text WITH syntax highlighting. Version 1.12.2, Windows 10.

@tedyun
Copy link

tedyun commented May 24, 2017

@rebornix I'd really appreciate if you can take a second look at this issue.

@rebornix
Copy link
Member

@tedyun we put both plain text and html in clipboard and it's the target application who decides which format to paste.

@ghost
Copy link

ghost commented May 29, 2017

@rebornix when copying codes into OneNote2016, indentation(using spaces) will get lost.
indentation

It seems that OneNote will ignore 'white-space: pre;'. Get   solution back, perhaps?

@xyzdata
Copy link

xyzdata commented Jun 27, 2017

I'd like to using sublime text 3 format paste!

Ctrl+Shift+V

How to realize it in VScode ?

@eckdanny
Copy link

eckdanny commented Jul 8, 2017

@rebornix @Meligy on Outlook for Mac (v15.35) I can get formatted text into an email if I spam the crap out of paste cmd (below)

spam-outlook-with-cnp

I can detect visually a FOUC-like render of the formatted paste under normal conditions too (one can see in the screen cast too). Surely there must be a way to disable the sanitizing that Outlook is doing in Outlook prefs, rt? (If anyone knows, plz share)

Definitely not a problem with VSCode... i just really want to be able to paste syntax-highlighted snippets in company email 😞

@pcgeek86
Copy link

pcgeek86 commented Jul 8, 2017

@eckdanny You don't need to spam the paste key combo. Just paste once, and then notice the little icon that appears after your paste. Click the icon and change it to "keep source formatting."

@darthwalsh
Copy link

darthwalsh commented Oct 19, 2017

@aptend you can paste into Word, copy, and paste into OneNote. If you remove the dark text background color the text colors are too light to see, but you can change VS Code to a light theme before copying ;)

I also found a few OneNote requests in UserVoice that everybody should upvote:

@SirwanAfifi
Copy link

It doesn't work with OneNote 2016!

@vscodebot vscodebot bot locked and limited conversation to collaborators Nov 17, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feature-request Request for new features or functionality
Projects
None yet
Development

No branches or pull requests