How to sort items from shortest to longest

sublimetext, sublimetext3

Solution

You have a couple of options.

There is a thread on the Sublime Text forum in which a user provides plugin code (disclaimer: I haven't actually tried it myself):

 import sublime, sublime_plugin
 import sort

 def line_length_sort(txt):
     txt.sort(lambda a, b: cmp(len(a), len(b)))
     return txt

 class SortLinesLengthCommand(sublime_plugin.TextCommand):
     def run(self, edit, reverse=False, remove_duplicates=False):
         view = self.view

         sort.permute_lines(line_length_sort, view, edit)

         if reverse:
             sort.permute_lines(sort.reverse_list, view, edit)

         if remove_duplicates:
             sort.permute_lines(sort.uniquealise_list, view, edit)

You can install the SortBy plugin. It provides many advanced sorting commands, including `SortBy: Length of lines`.

On Windows:

Sort By String Options & Key Bindings

Ctrl + Alt + Shift + R SortBy: Alphabetically Ascending

Ctrl + Alt + Shift + T SortBy: Alphabetically Descending

Ctrl + Alt + Shift + W SortBy: LengthOf Lines Ascending

Ctrl + Alt + Shift + E SortBy: LengthOf Lines Descending

Ctrl + Alt + Shift + Q SortBy: Natural Order Ascending

Sort By Number Options & Key Bindings

Ctrl + Alt + Shift + S SortBy: Binary Ascending

Ctrl + Alt + Shift + D SortBy: Binary Descending

Ctrl + Alt + Shift + I SortBy: Hexadecimal Ascending

Ctrl + Alt + Shift + O SortBy: Hexadecimal Descending

Ctrl + Alt + Shift + Y SortBy: Interger Ascending

Ctrl + Alt + Shift + U SortBy: Interger Descending

Ctrl + Alt + Shift + P SortBy: Octal Ascending

Ctrl + Alt + Shift + A SortBy: Octal Descending

Menu Location:

Problem

In Sublime Text, is there any way to sort items below to shortest to longest? I don't know if this helps, but I am using Vintage mode. ``` use App\Article; use App\Http\Controllers\Controller; use App\Http\Requests\ArticleRequest; use App\Tag; use App\User; use Gate; use Illuminate\Http\Request; use Illuminate\Support\Facades\Auth; use Intervention\Image\Facades\Image; use Mews\Purifier\Facades\Purifier; ``` What I am trying to achieve is that select all the items, trigger some command and have them sorted shortest to longest

Original source