Smart SortSort CSV-like words or lines in Visual Studio Code. SummarySmart Sort allows you to:
Smart Sort chooses how and what to sort according to the selection state so there are just 2 commands provided: one for sorting ascending order, one for sorting descending order. For default key bindings, see "Key bindings" section. Smart Sort recognizes numeric values so FeatureSorting wordsTo sort words, just select some words and hit Ctrl+Alt+R (or Cmd+Ctrl+R on mac.) Smart Sort automatically recognizes the word separator. In order of priority, supported separators are:
On sorting words, word separators among them will be normalized. Strictly writing, whitespace characters surrounding the first word separator will be treated as part of the separator and they will be used to separate sorted words. Here are some example animations:
Sorting linesTo sort lines, select multiple lines and hit Ctrl+Alt+R (or Cmd+Ctrl+R on mac.) If you select portions of lines by using
multple selections (multi-cursor),
the lines which are touched by the selection range will be sorted by comparing
the selected parts.
This is useful if you want to sort on arbitrary column of visually aligned text
data such as output of
Here are some example animations:
Sorting words spread over multiple lineIf
In this mode, sorted words will be reflowed. In other words, the original indentation and line widths will remain unchanged. (for example, the indentation characters of the second line is kept unchanged in the example animation below). Note that if you place both the start and end of the selection range are placed
at a beginning of a line, you can always sort lines even if you set
Here is an example animation:
Contribution PointsCommandsSmart Sort provides the commands below:
By default key bindings are automatically defined for those commands. Key bindingsSmart Sort provides the default keybindings below:
Configuration
Historical BackgroundPreviously the name of this extension was "Stable Sort". Here is why I wanted and created an extension which uses stable sort algorithm. Back when Visual Studio Code was version 1.27.2, it have used unstable sort algorithm. This means that sorting textually identical words or lines may change those order. This behavior will not be a problem in most cases since swapping those is not a change by all means. Unfortunately, I encountered an exceptional case. In Japanese locale, an ASCII digit character and its counter part in fullwidth forms are treated as equal so the order of words like below changed every time I sort them:
This behavior was very annoying when I was compositing dictionary data since I cannot normalize entries by simple sorting. Obviously an extension which allows me to sort entries using stable sort algorithm solves the problem. So, I created one. |