visual-studio 从 Visual Studio 复制粘贴代码,但粘贴未格式化的代码

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/516441/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-22 10:08:10  来源:igfitidea点击:

Copy-paste code from Visual Studio, but paste UNFORMATTED code

visual-studiovisual-studio-2008visual-studio-2005copy-paste

提问by Richard Ev

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

有没有办法强制 Visual Studio 将所选代码作为无格式文本复制到剪贴板?

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!

当我将代码复制粘贴到 Word 或更频繁的 Outlook 中时,我必须通过记事本来删除格式……必须有更简单的方法!

采纳答案by Rob Kennedy

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.)

Visual Studio 确实将未格式化的文本放置在剪贴板上,但它也会放置格式化的文本。(剪贴板支持多种同步格式,操作系统假定它们只是相同数据的不同表示,尽管没有技术强制执行这一点。)

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.

您用来粘贴的应用程序然后选择其首选格式。在 Word 和 Outlook 中,有一个“选择性粘贴”命令,可让您选择要使用的格式。

回答by Michael Paulukonis

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。坐在系统托盘中;复制文本,单击它 - 去除所有格式,留下普通文本。我确信它很像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."

“PureText 基本上相当于打开记事本,执行 PASTE,然后是 SELECT-ALL,然后是 COPY。PureText 的好处是使用单个热键执行所有这些操作,并将结果自动粘贴到当前窗口中.”

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....

这样做的原因是片状的 Lotus Notes;在粘贴我无意中从网页上复制的 HTML 标记文本时喜欢崩溃....

回答by Idan Shechter

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.

如果在粘贴后按 CTRL+Z,它将反转为非格式化的,因为格式化实际上是在常规粘贴后计为一步。

回答by Ted

From this blog postI 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).

这篇博客文章中,我得到了这些说明,用于在激活“深色主题”的情况下复制和粘贴出 VS 时摆脱黑色背景,但可以调整其中的 html 以根据需要更改其余格式(例如设置所有文本为黑色)。

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

打开工具 → 扩展和更新

选择 Online (Visual Studio Gallery) 并搜索 Productivity Power Tools 2012/2013

出现提示时下载并重新启动 Visual Studio

Productivity Power Tools Settings

生产力电动工具设置

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

Change the BeforeCodeSnippet option to:

打开工具 → 选项 → 展开生产力 Power Tools 选择 HTML Copy

将 BeforeCodeSnippet 选项更改为:

<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

将 EmitSpanClass 更改为:True

检查 EmitSpanStyle 为:True

回答by Marcel

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

用于的 Visual Studio 扩展副本可能对您很方便。实际上,它不会进行无格式复制,而是应用它自己的简单的基于文本的模板。

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 Galleryand try it out.

Visual Studio Gallery 中获取并试用。

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

披露:我是该扩展的作者。请通知我,如果我可以改进它以满足您的需求。

回答by Marcel

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.

当我这样做时,选择附加到小剪贴板项目“匹配目标格式”的小弹出菜单选项对我有用。

回答by Brian

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.

您可能会发现http://www.extrabit.com/plaintextclipboard/是一个有用的工具。一些应用程序有一个粘贴选项,可以去除格式,但您真正需要的是去除格式的复制操作,而 VS 不提供。

回答by Ryan MacLachlan

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]

在 Outlook 2007 中,我已将默认粘贴更改为仅粘贴文本。转到编辑器选项 | 高级在“剪切、复制、粘贴”标题下选择从其他程序粘贴:[仅保留文本]

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

如果您仍然想粘贴格式化(在我的情况下不太常见),请使用特殊粘贴...

回答by Michael

This Microsoft Office siteoffers 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.

此 Microsoft Office 站点提供了一种解决方法,包括编写宏来替换 ctrl+v 功能以始终粘贴纯文本,但这可能不是您想要的。您也可以重新映射未使用的快捷方式 (ctrl+?) 来为您提供此功能,这样您就不必继续启用/禁用宏。

回答by Rich Alger

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

对于没有“特殊粘贴”的应用程序,您可以使用像PureText这样的应用程序