How do you sort a range of lines by length?

前端 未结 3 669
情深已故
情深已故 2020-12-29 02:39

Often I just want to sort all my #include\'s at the top of my source and header files by their length.

vim allows me to sort alphanumerical

3条回答
  •  天涯浪人
    2020-12-29 03:12

    Filter Visual Selection with Awk

    One way to do this in vim is by filtering the visual selection with awk's length() function before sorting. For example:

    :'<,'> ! awk '{ print length(), $0 | "sort -n | cut -d\\  -f2-" }'
    

提交回复
热议问题