ctrl+shift+p filters: :st2 :st3 :win :osx :linux
Browse

Sort Lines By Selection

by Zeeker ST3

A line sort plugin for Sublime Text 3 which enables you to sort lines based on the selected text in the line

Details

Installs

  • Total 2K
  • Win 1K
  • OS X 834
  • Linux 447
Oct 23 Oct 22 Oct 21 Oct 20 Oct 19 Oct 18 Oct 17 Oct 16 Oct 15 Oct 14 Oct 13 Oct 12 Oct 11 Oct 10 Oct 9 Oct 8 Oct 7 Oct 6 Oct 5 Oct 4 Oct 3 Oct 2 Oct 1 Sep 30 Sep 29 Sep 28 Sep 27 Sep 26 Sep 25 Sep 24 Sep 23 Sep 22 Sep 21 Sep 20 Sep 19 Sep 18 Sep 17 Sep 16 Sep 15 Sep 14 Sep 13 Sep 12 Sep 11 Sep 10 Sep 9 Sep 8
Windows 0 0 0 0 1 0 1 3 2 0 0 1 3 0 1 1 0 1 3 1 0 0 1 0 0 1 0 4 0 2 0 1 2 1 1 0 0 0 0 1 2 0 0 0 0 0
OS X 0 0 0 0 1 0 3 0 0 0 0 0 1 3 4 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 1 1 1 1 0 0 1 1 1 1 1 0 0 0
Linux 0 1 0 0 2 1 0 2 0 0 0 1 0 0 0 0 0 2 0 1 0 0 1 0 0 0 0 0 1 2 0 0 0 0 1 0 0 0 0 0 1 1 1 0 0 1

Readme

Source
raw.​githubusercontent.​com

Selection Sorter

Did you ever want to sort some class members via their names, easily, or a number of lines via a string in the middle? Well, now you can.

This plugin enables you to sort lines by the text you have currently selected.

Default Commands

It ships with two commands you can find in the command palette:

  • Sort Lines by Selection
  • Sort Lines by Selection (Case Sensitive)

Customization

The plugin supports custom morphing of the selected strings before sorting, via little python snippets. For example you could reverse the string which is used for sorting, sort via the last character, only via the first etc..

You can make your custom sort available by creating a Default.sublime-commands file in your packages/user folder, or alternatively a keybinding which executes the command.

Example

Here a little example for a custom line sort:

Default.sublime-commands

[
        {
            "caption": "Sort Lines by Selection",
            "command": "sort_lines_by_selection",
            "args": {
                "morph": "s[::-1]" // This will reverse the string
            }
        }
    ]

As you can see I reference a variable s (a string) and reverse it. This would sort the lines by the reversed selection. So a line with a selection of “AZZZZ” would be at the bottom, rather than at the top.

Note however that only a single statement is allowed, otherwise your custom morph will not work.

Technically speaking the morph argument is the “body” of a python lambda, and will be used as the key argument of the built-in sorted function.

Happy sorting!