Currently VS has a very useful feature: sort usings (C#).
I want the same functionality for any random text, for example - XML nodes in config files.
How complex to implement that? VS addin, right? Is it possible to call some VS API which is used for sorting usings?
Select the lines you want and then press: Windows: Shift + Alt + i. Mac: shift + option + i.
To display the Output window whenever you build a project, in the Options dialog box, on the Projects and Solutions > General page, select Show Output window when build starts.
VS Code blocks saving the file to prevent overwriting changes that have been made outside of the editor. Use the actions in the editor toolbar to resolve the save conflict. You can either Accept your changes and thereby overwriting any changes on disk, or Revert to the version on disk.
A nice AddOn for Visual Studio is Code Maid
You select some lines and chose from Context Menu "Sort Lines"
And voilá, your lines are sorted nicely in alphabetical order:
Edit: Note that this solution does not work on VS2013 or higher, since support for macros was removed.
You don't necessarily need to code a VS addin to do this: Visual Studio has macros built in. To get started, use Tools, Macros, Record Temporary Macro.
Here's a 'Sort Lines' command I hacked together based on the code that Record Temporary Macro gave me:
Imports System Imports EnvDTE Public Module TimModule Sub SortLines() Dim Selection As TextSelection = DTE.ActiveDocument.Selection Dim Lines() As String = Selection.Text.Replace(Environment.NewLine, Chr(13)).Split(Chr(13)) Array.Sort(Lines) DTE.UndoContext.Open("Sort Lines") ' Edit - see comments ' Selection.Text = String.Join(Environment.NewLine, Lines) Selection.Delete Selection.Insert(String.Join(Environment.NewLine, Lines)) DTE.UndoContext.Close() End Sub End Module
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With