I have the following input file:
abcde
abc
abcdef
abcd
that I would like to sort by line-length. I can do this by running the command 1,4!awk '{print length, $0}' | sort -n -s | cut -d' ' -f2 which gives the output:
abc
abcd
abcde
abcdef
Now I want to create a user-defined command SortL that will do exactly the same as above:
command! -count SortL <count>!awk '{print length, $0}' | sort -n -s | cut -d' ' -f2-
However when I run 1,4SortL on the input file I get:
abcde
abc
abcdef
abcd
no changes were made so I must have made a mistake on the definition of SortL. How to define SortL so that lines get sorted by length?
:h command-range. What you try to pass is a range, not a count. So it is-rangenot-countand<line1>,<line2>instead of<count>