63

Is there any way to force Visual Studio to copy selected code to the clipboard as unformatted text?

When I am copy-pasting code into Word or more often Outlook I have to do it via Notepad to get rid of the formatting...there has to be an easier way!

Richard Ev
  • 52,939
  • 59
  • 191
  • 278

13 Answers13

43

This feature can be turned off by editor.copyWithSyntaxHighlighting.

aosaimy
  • 541
  • 4
  • 3
25

Visual Studio does put unformatted text on the clipboard, but it also puts formatted text. (The clipboard supports multiple simultaneous formats, and the OS assumes that they're simply different representations of the same data, although there's no technical enforcement of that point.)

The application you're using to paste then chooses its preferred format. In Word, and maybe Outlook as well, there is a "Paste Special" command that allows you to choose which format you want to use.

Rob Kennedy
  • 161,384
  • 21
  • 275
  • 467
  • Paste Special is the way I do it – revs Feb 05 '09 at 15:59
  • For some reason "Paste Special" always seems to be disabled in Outlook 2003 – Richard Ev Feb 06 '09 at 09:14
  • It's enabled for me in Outlook 2007, so I don't know what else to say. Good luck. – Rob Kennedy Feb 06 '09 at 18:23
  • Patrick, the applications that don't support "paste special" are also usually the ones that don't support formatted text anyway. They'll always select the unformatted text because that's the only thing they check for and the only thing they support. – Rob Kennedy Aug 06 '09 at 22:04
  • 1
    Unfortunately, that isn't true about Microsoft Office Communicator, which I paste into all the time. – Patrick Szalapski Aug 07 '09 at 13:23
  • I'm with Patrick on this one, office communicator is annoying for that reason, it takes the formatted version but doesn't allow you to use Paste Special... – ColinCren Sep 10 '14 at 17:16
19

My department uses PureText. Sits in the system tray; copy text, click-it - strips all formatting leaving the plain-vanilla text. I'm sure it's much like PlainTextClipboard.

"PureText is basically equivalent to opening Notepad, doing a PASTE, followed by a SELECT-ALL, and then a COPY. The benefit of PureText is performing all these actions with a single Hot-Key and having the result pasted into the current window automatically."

The goad for this was flaky Lotus Notes; likes to crash when pasting HTML-marked-up-text that I innocently copied from a web-page....

Michael Paulukonis
  • 9,020
  • 5
  • 48
  • 68
  • 1
    Beautiful and free! I expected it from your description to be payware and was going to sit up tonight and make a free replacement, yet lo and behold, it's free software! Thanks for sharing: ) – Mahmoud Al-Qudsi May 10 '10 at 22:48
  • @PaulMolloy - I'm still using it, only I've got it mapped to Windows-V to paste unformatted text. I totally missed using the hotkeys option until recet months. Doh! – Michael Paulukonis Nov 18 '16 at 15:56
14

If you press CTRL+Z after pasting, it will reverse to the non-formatting one, because the formatting actually counts as one step after the regular paste.

Liron Harel
  • 10,819
  • 26
  • 118
  • 217
  • 10
    Though this may be by convention in Microsoft products, this is not the case for other applications. – Slate Sep 07 '18 at 14:18
3

Search editor.copyWithSyntaxHighlighting in Settings and disable it. Whoever enabled it by default must be flogged.

Boss Man
  • 587
  • 2
  • 12
2

From this blog post I got these instructions for getting rid of the black background when copying & pasting out of VS with the 'Dark Theme' activated, but the html in it can be tweaked to alter the rest of the formatting as required (e.g. set all text to black).

If required, install Productivity Power Tools

Open Tools → Extensions and Updates

Select Online (Visual Studio Gallery) and search for Productivity Power Tools 2012/2013

Download and restart Visual Studio when prompted

Productivity Power Tools Settings

Open Tools → Options → Expand Productivity Power Tools select HTML Copy

Change the BeforeCodeSnippet option to:

<style type="text/css">.identifier {color:black !important;}</style>
<pre style="{font-family}{font-size}{font-weight}{font-style}">

Change EmitSpanClass to: True

Check EmitSpanStyle is: True

Ted
  • 2,525
  • 2
  • 37
  • 54
2

When I do it choosing the little pop-up menu option attached to the wee clipboard item "Match Destination Formatting" does the trick for me.

  • Office 2003 features that option in Word, but not Outlook. (I think that Outlook 2007 has it though...) – Richard Ev Feb 06 '09 at 09:12
  • Well why not set the format of the mail to plain text? Or do you have some fancy signature with bold and hyperlinks and what have you? –  Feb 06 '09 at 09:47
  • Fancy signature...oh yes! Our corporate standard signature uses Arial in a specific shade of blue, formatted in an HTML table with our company logo... – Richard Ev Feb 06 '09 at 17:58
1

You might find http://www.extrabit.com/plaintextclipboard/ to be a useful tool. Some applications have a paste option which strips formatting, but what you really need is a copy operation that strips formatting, which VS does not offer.

Brian
  • 25,523
  • 18
  • 82
  • 173
  • I've seen this called a "clipboard scrubber". A similar program is ClipboardFusion - http://www.binaryfortress.com/clipboardfusion/ . Instead of copy-paste, the operation becomes copy-paste-realize it is ugly-scrub clipboard-paste. – Patrick Szalapski Aug 06 '09 at 21:07
  • 1
    Or PureText, as another answer suggested. – Patrick Szalapski Aug 06 '09 at 21:19
1

In Outlook 2007, I've changed my default paste to do text only. Go to Editor Options | Advanced Under the "Cut, copy, paste" heading choose Pasting from other programs: [Keep Text Only]

And if you still want to paste formatted (less often in my case), use paste special...

0

For applications that do not have a "paste special" you could use an application like PureText

Rich Alger
  • 21
  • 5
0

The Visual Studio Extension Copy for review may be handy for you. Actually, it does not do unformatted copying, but applies it's own simple text-based template.

It supports a "Stack Overflow" format, which just removes the leading whitespace, while keeping the indentation as much as possible, and introduces some sort of header.

Get it from the from the Visual Studio Gallery and try it out.

Disclosure: I am the author of that Extension. Please notfiy me, if I can improve it to your needs.

Marcel
  • 15,039
  • 20
  • 92
  • 150
0

This Microsoft Office site offers a workaround that involves writing a macro to replace ctrl+v functionality to paste plain text all the time, but that may not be what you want. You can alternatively remap an unused shortcut (ctrl+?) to provide you with this functionality so you don't have to keep enabling / disabling the macro.

Michael
  • 3,099
  • 4
  • 31
  • 40
0

A trick when applies:

  • You don't want to install an extension
  • Your destination application doesn't have options such as "Paste Special"..

You can copy the code and paste it in VS Code search box (shows when you press Ctrl+F). Then copy it again from there.

Then you can paste unformatted text anywhere you want.

zhm
  • 3,513
  • 3
  • 34
  • 55