How to sort following text starting from column 5:
123456789
000 123
013 122
122 013
123 000
I want to get this:
123 000
122 013
013 122
000 123
123456789
The following vim command helped me:
:sort /\%5v/
besides some plain options (like u,i,!,n) sort can receive regular expression /{pattern}/. In this case there are two options:
default - with no [r] flag specified - in this case for each line the text matched with {pattern} is skipped, so sort is done on what comes after the match.
Examples from documentation:
A1. Example - sort starting from virtual column 5 our case - sort on the text at virtual column 5 (thus ignoring the difference between tabs and spaces):
:sort /.*\%5v/
A2. Example - sort on the second comma-separated field
The logic is: skip text until first comma is found:
:sort /[^,]*,/
i.e. sorting is done on the matching {pattern} instead of skipping past it as described above ... to sort on only the first three letters of each line:
:sort /\a\a\a/ r
Please check :help :sort for more details/options
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With