Sort selected text from Visual Studio context menu

Viewed 28256

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?

7 Answers

VS 2019 & VS 2022:

  1. Select lines. The last selected line is where the cursor is - the line is taken into account even if it is empty and there is no visible selection.
  2. Shift + Alt + L, Shift + Alt + S => Ascending sort.
  3. Shift + Alt + L, Shift + Alt + S (same selection same keys) => Descending sort.

The command can also be invoked from menu (@sharpener): Edit | Advanced | Sort Lines

This comes up at the top of searches still so I'll add this latest solution. If you are running a current VS Code (and why wouldn't you?) you can use the built-in sorter by hitting ctrl-shift-p (Mac is cmd-shift-p) and type "sort" in the subsequent search box. There are many options.

Related