News

Visual Studio Dev Requests Code Copying with Proper Indentation, Mads K. Delivers

Microsoft's Visual Studio extension guru Mads Kristensen is at it again, taking a developer request and turning it into a handy tool, which he has put out there for experimentation and feedback.

This time he addressed an August 2020 post in Microsoft's Developer Community site for bug reports, feature requests and so on. Under the title "Easy copy code without indentation," the item from Thomas Ardal reads (unedited):

If often need to copy code from within Visual Studio and paste it into a blog post, some documentation, etc. When copying from indented code files (like a method in a class in a C# file) you get the spaces (or tabs) from the beginning of each line copied as well. Cleaning up these extra tabs after paste is boring work. To avoid doing that, I often mark the code I want copied and shift+tab the code until it is left aligned in the file and make a copy. Then ctrl+z to snap it back into place. It would be nice with a special shortcut, button, or something else that copies code so that it looks good pasted.

Yesterday (Oct. 25), Kristensen announced his solution, the Copy Nice extension in the Visual Studio Marketplace.

Copy Nice
[Click on image for larger view.] Copy Nice (source: Microsoft).

"You want to share some code you've written with a colleague, so you select it in the editor and hit Ctrl+C to copy it," he said in a blog post. "As you paste it in Outlook/Slack/Teams, you realize that the indentation levels are inconsistent due to your original selection. You must now either go back to Visual Studio and do a box selection and copy that, or manually fix the indentation issue in Outlook. You know this, yet you make this mistake almost every time. Sounds familiar?"

As an experiment, he worked up Copy Nice to remove unwanted indentation when code is copied from the editor, which required dealing with the thorny question of how the tool can be used for just unwanted indentations as opposed to wanted indentations. In addition to a code copy including indentation that needs to be manually stripped out later, another type of problem typically occurs when a developer neglects to include leading indentation when selecting text, instead pointing the cursor to the start of the text instead of capturing that indentation character to the left. That fails to capture indentation that may be wanted.

Kristensen indicated that annoying code copying indentation problems are commonplace, noting that multiple developers have requested a feature to address them, in addition to the August 2020 request from Ardal. Indeed, his post has garnered 68 votes and 13 comments.

Code Copying Indentation Hassle in Animated Action
[Click on image for larger, animated GiF view.] Code Copying Indentation Hassle in Animated Action (source: Thomas Ardal).

The tool itself, released on Oct. 12 and updated yesterday, was nearing 440 installs at the time of this writing and earned an average 4.8 rating (0-5 scale) from six developers who reviewed it. One said: "Simple, yet effective. Works as advertised. This is especially useful when doing code reviews or pasting code into markdown format or in MS Teams. This fixes that super annoying removing formatted space. Lovely!"

Kristensen, who has authored some 185 extensions in the VS Marketplace, is now seeking more feedback on Copy Nice.

"If this feature is interesting to you, please install the Copy Nice extension and take it for a ride. Make sure to share any ideas and bugs on the GitHub issue tracker, and feel free to send pull requests too. The feature request ticket is a suitable place to share your comments and thoughts, so make sure to vote and comment there as well."

Kristensen's new Copy Nice tool essentially duplicates functionality in his Tweaks extension, he indicated.

About the Author

David Ramel is an editor and writer for Converge360.

comments powered by Disqus

Featured

  • AI for GitHub Collaboration? Maybe Not So Much

    No doubt GitHub Copilot has been a boon for developers, but AI might not be the best tool for collaboration, according to developers weighing in on a recent social media post from the GitHub team.

  • Visual Studio 2022 Getting VS Code 'Command Palette' Equivalent

    As any Visual Studio Code user knows, the editor's command palette is a powerful tool for getting things done quickly, without having to navigate through menus and dialogs. Now, we learn how an equivalent is coming for Microsoft's flagship Visual Studio IDE, invoked by the same familiar Ctrl+Shift+P keyboard shortcut.

  • .NET 9 Preview 3: 'I've Been Waiting 9 Years for This API!'

    Microsoft's third preview of .NET 9 sees a lot of minor tweaks and fixes with no earth-shaking new functionality, but little things can be important to individual developers.

  • Data Anomaly Detection Using a Neural Autoencoder with C#

    Dr. James McCaffrey of Microsoft Research tackles the process of examining a set of source data to find data items that are different in some way from the majority of the source items.

  • What's New for Python, Java in Visual Studio Code

    Microsoft announced March 2024 updates to its Python and Java extensions for Visual Studio Code, the open source-based, cross-platform code editor that has repeatedly been named the No. 1 tool in major development surveys.

Subscribe on YouTube