Tyriar / vscode-sort-lines

Visual Studio Code extension to sort lines of text
https://marketplace.visualstudio.com/items/Tyriar.sort-lines
MIT License
146 stars 42 forks source link

Multilevel support #94

Open lavermil opened 3 years ago

lavermil commented 3 years ago

Can you add the support to do single and multilevel block sorts. So you will sort based on the parent (non-indented lines) but also have an option to sort the children and any other sub-levels too.

This is very helpful in the world of comparing network device, application configs, etc using diff tools. Sometime as different version come out and they change config files/etc around the order of stuff/etc. Without this python script I have below it is very hard to compare them.

My method in python I am using allows me to specify what the indent pattern is. For example if you want to use a tab, 2 space, 3 space, 4 spaces, etc. I have also added in python the ability to filter out lines like ! or # or what ever I want as long as it is an exact match.

Example:

Parent3
!
Parent2
  child1
    child1c
    child1a
    child1b
!
Parent1
  child2
    child2b
      child1a
      child1c
      child1b
    child2a
      child1b
      child1a
      child1c
  child1

Desired:

Parent1
  child1
  child2
    child2a
      child1a
      child1b
      child1c
    child2b
      child1a
      child1b
      child1c
Parent2
  child1
    child1a
    child1b
    child1c
Parent3
lavermil commented 3 years ago

Here is a sample config to play with too. sample_config.txt

leowill01 commented 2 years ago

+1 this would also be super useful for sorting markdown task lists where it could sort checked - [x] below unchecked - [ ] items while keeping tasks at the same indentation levels by ignoring whitespace preceding the task list syntax, e.g. regex = ^[:blank:]*.+.