Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Are there any good ways to copy code from Visual Studio that keeps the code neat looking? I have two main concerns that are large enough for me to raise this question:

  1. When copying multiple lines of code from a nested code block, the leading whitespace on every line should be removed. This one is easy to fix manually though, by simply using shift + tab until it aligns as it should. Still something I'd like to avoid though.
  2. More importantly, however, is when copying from code where the setting "replace with tabs" is used, the indetions will be huge when copied to e.g. Notepad, making the code practically unreadable.

I'm hoping for a one-click solution here, be it an Add In or Macro, that does not matter, as long as I can select a block of code, and then copy it with one click, and have it look well when I paste it somewhere else.

share|improve this question
Have you tried pasting the code into something else? For example Notepad++? – Shiki Jul 2 '12 at 22:35
@Shiki: I thought that was quite clear from my question. :) Yes, and my problem is mainly spacing, which I what I would like to control, or at least have a better default. – Johny Skovdal Jul 3 '12 at 6:29
Oh. Okay, sorry. Uhm... what about some kind of "Clipboard control"? Like writing a small C# application, that will run in the tray, and use that with a hotkey. So when you copy from VS, you get the format you want. .... hmmm.. maybe it's an overkill, but hey, better than nothing! – Shiki Jul 3 '12 at 10:54
up vote 3 down vote accepted

The Visual Studio Extension Copy for review may help you out

It currently supports two output formats, both removing leading whitespace, while keeping the indentation as much as possible.

Example: The following code (verbatim copy)

        foreach (OrderByInfo orderByInfo in ParseOrderBy(orderBy)) {
            collection = ApplyOrderBy<T>(collection, orderByInfo);

will get formatted to (using the Stack Overflow output format):


Here's my code (in OrderByHelper.cs):

foreach (OrderByInfo orderByInfo in ParseOrderBy(orderBy)) {
    collection = ApplyOrderBy<T>(collection, orderByInfo);


However, syntax highlighting does only work on the site, not here on It's a feature of the site, not the extension.

Get the extension from the from the Visual Studio Gallery.

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

share|improve this answer
Thanks, I'm very impressed with that solution so far! The only thing missing, as I see it, is a copy option that includes the code markup for syntax highlighting here on StackOverflow. :) – Johny Skovdal Mar 20 '15 at 6:48
@JohnySkovdal Syntax highlighting is not supported here on Super User. I have added that to the answer, plus made an example. – Marcel Mar 20 '15 at 8:13

If HTML output is okay, there is an extension called Copy as HTML.

share|improve this answer
For most scenarios that won't work no, but thank you for pointing this one out though, it certainly can come in handy. :) – Johny Skovdal Jul 3 '12 at 6:33

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.