How can I sort by line size in Sublime Text?

3

I would like to know if there is any way to sort the line by its size in Sublime Text .

Because I have code like this:

use ArrayAccess;
use ArrayIterator;
use IteratorAggregate;
use Countable;
use Closure;
use JsonSerializable;
use Laravel\Database\Eloquent\Model;

And I would like to leave it like this, in a "click" (or shortcut)

use Closure;
use Countable;
use ArrayAccess;
use ArrayIterator;
use JsonSerializable;
use IteratorAggregate;
use Laravel\Database\Eloquent\Model;
    
asked by anonymous 14.07.2015 / 17:48

2 answers

3

I do not know if it is a good idea to do this, it may seem cute but the ideal is to order by relevance of use. But if you really want to find a code in their forum :

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 also have plugin ready .

    
14.07.2015 / 17:57
2

There is a plugin that you can add in sublime-text : SortBy - Github

    
14.07.2015 / 17:56