I have a very long script that contains a huge list of brand names that is not in alphabetical order. The result of many different people working on it over a few years :) Question - is there a way to re-order lines of code alphabetically in Visual Studio Code (VSCode)? I know this is possible for single lines of code, but is it possible for multi-line blocks of code that have been indented? See attached example - so in this case I would be looking to select all these lines of code and sort by the brand name (acer, acqua, aeg, amazon etc) and retain the nested parts of the code for each. Many thanks in advance if anyone has any ideas or suggestions
Screenshot of code to be sorted
I tried sorting in VSCode, but it only sorts individual lines of code and mixes them together. It does not recognize multiline, nested blocks of code as being one group of code that can be sorted individually
CodePudding user response:
[Assuming you have a json object or could your text into one. Looks very close already - if it isn't json you might consider making a separate file and make it json, so you can use a sorter.]
I see a number of json sorters in the Marketplace: just search for json sort
.
This one has 280K downloads: Sort JSON Objects
And I see a couple more. There is no built-in way to do what you want, you will need an extension.
CodePudding user response:
I would:
- Replace new line 3x -
\n\t\t\t
- with an empty string - Sort
- Format document (you may need to Change Language Mode first)