Download Pretty Paste now!

One of the things that have annoyed me about Visual Studio for many years, is the inconsistency when pasting code copied from websites. Depending on the browser you get different results. Consider the code snippet below copied from one of Sayed’s blog posts.

image

If I copy that from Internet Explorer and paste it into Visual Studio, this is what I get:

image

And copied from Chrome result in this:

image

As you can see, both browsers include the line numbers, but they interpret them differently. Both browsers fail to understand my intent for copying the text and it has been that way forever. Very annoying. In tooling, understanding the user’s intent is the holy grail.

So, in a rare moment of clarity a few days ago, I decided to fix this issue by writing an extension for Visual Studio - Pretty Paste. The idea is to inject some logic just before the regular Paste command in VS executes. That logic will quickly analyze the text being pasted and correct any non-intended line numbers and extra blank lines.

With Pretty Paste, the result of pasting the above code sample now shows this:

image

It automatically formats the code I pasted using the settings from each individual language. Here, my settings are set to use spaces instead of tabs and that is respected.

In the case where you actually wanted the raw copied text instead of the cleaned up version provided by Pretty Paste, you can just undo the paste once to get the raw paste. Here’s the result of a Pretty Paste followed by an undo:

image

This way we can have the best of both worlds. You decide. Nothing is lost.

Pretty Paste is my 6th Visual Studio extension and I love that extensibility let’s me fix use cases that are important to me. The code is simple, short and sweet. Check it out on GitHub and fork away. Pull requests are more then welcome.

Comments

Kumar

- Go to Sayed’s blog - Hover over the code block - Three icons will pop in right top corner - Click on first icon "View source" - Copy the source and paste it anywhere you like - Works in all browers - Works with all IDEs

Kumar

Topbot

Also its good to post code with special link for source coping. My site for codeposting - http://s-c.me, simular to pastebin.com

Topbot

Phil

Hi Mads; I've installed into VS2012, and found a defect. Is it just me? Copying items from a browser gives me this: RouteTable.Routes.MapHubs();.MapHubs; instead of RouteTable.Routes.MapHubs(); Confirmed this behaviour exists when Pretty Paste is enabled, and doesn't exist when it's disabled. Any more info I can give you to help track down?

Phil

Ian Obermiller

Nice idea! I never thought to solve this at the editor level, but this certainly would make things easier. @Kumar: not all code snippets are as well behaved; also, I don't want to go through so many steps just to copy-paste some code. On a side note, if you are actually going to use the code and aren't just testing something, I highly recommend typing it out by hand to increase comprehension.

Ian Obermiller

Todd Knudsen

Thanks Mads! Simple things make all the difference.

Todd Knudsen

dirkstrauss.com

Pingback from dirkstrauss.com The Daily Six Pack: March 27, 2013 | Dirk Strauss

dirkstrauss.com

Someone

Superb....! Why to worry so much when it is already available....! :)

Someone

Behamooz

the comments on google analytics are closed. does your code works on new google analytics script? http://www.google-analytics.com/analytics.js the script of new analytic is diffrent from the one that you put in ashx file.

Behamooz

Speed Dating NYC

This is a very nice idea! Thanks

Speed Dating NYC

roelvanlisdonk.nl

Pingback from roelvanlisdonk.nl Nice Visual Studio extension: Pretty Paste

roelvanlisdonk.nl

Comments are closed