You could use external commands to do that. Take for example, giving that the buffer has only the content you share the following commands:
%!awk -F ',' '{print length($1) "|" $0}'
%!sort -nr
%norm df|
would result in this contents:
"Be(C<sub>5</sub>H<sub>7</sub>O<sub>2</sub>)<sub>2</sub>","Be acetylacetonate");
"Mn(CHO<sub>2</sub>)<sub>2</sub>·2H<sub>2</sub>O","Mn formate dihydrate");
"Cu(BrO<sub>3</sub>)<sub>2</sub>·6H<sub>2</sub>O","Cu bromate hexahydrate");
"Bi(NO<sub>3</sub>)<sub>3</sub>·5H<sub>2</sub>O","bismuth nitrate pentahydrate");
"O<sub>2</sub><sup>2−</sup>","Peroxide#Inorganic chemistry|peroxide ion");
first, with awk, we can determine and prepend on each line the lenght of the first field, so after the first command (%!awk -F ',' '{print length($1) "|" $0}'
) your buffer will look like:
48|"Bi(NO<sub>3</sub>)<sub>3</sub>·5H<sub>2</sub>O","bismuth nitrate pentahydrate");
57|"Be(C<sub>5</sub>H<sub>7</sub>O<sub>2</sub>)<sub>2</sub>","Be acetylacetonate");
34|"O<sub>2</sub><sup>2−</sup>","Peroxide#Inorganic chemistry|peroxide ion");
49|"Cu(BrO<sub>3</sub>)<sub>2</sub>·6H<sub>2</sub>O","Cu bromate hexahydrate");
49|"Mn(CHO<sub>2</sub>)<sub>2</sub>·2H<sub>2</sub>O","Mn formate dihydrate");
Then, we can sort it with the sort program, so, after the second command (%!sort -nr
), your buffer would look like this
57|"Be(C<sub>5</sub>H<sub>7</sub>O<sub>2</sub>)<sub>2</sub>","Be acetylacetonate");
49|"Mn(CHO<sub>2</sub>)<sub>2</sub>·2H<sub>2</sub>O","Mn formate dihydrate");
49|"Cu(BrO<sub>3</sub>)<sub>2</sub>·6H<sub>2</sub>O","Cu bromate hexahydrate");
48|"Bi(NO<sub>3</sub>)<sub>3</sub>·5H<sub>2</sub>O","bismuth nitrate pentahydrate");
34|"O<sub>2</sub><sup>2−</sup>","Peroxide#Inorganic chemistry|peroxide ion");
Then you clean your lines with %norm df|
that way you end up with your lines sorted by first field length.
If it is just part of a bigger file, you can use visual mode to select the lines you want to sort and then press colon and the same commands but without the percent symbol. The commands then would start with: '<,'>
. For example, the first command would look like '<,'>!awk -F, '{print length($1) "|" $0}'
This probably won't work on windows though