I have a vim file that looks like the following:
ABBA
Duran Duran
The Beatles
The Rolling Stones
Styx
Using vim's sort command results in this output:
ABBA
Duran Duran
Styx
The Beatles
The Rolling Stones
What I want to do is to ignore articles like 'A' and 'The' when sorting. So expected output would be like this
ABBA
The Beatles
Duran Duran
The Rolling Stones
Styx
Sorting text in Vim is easy! Select the text, then press : , type sort , then hit enter! It'll sort the whole document by default, but you can enter a range too.
column happens to be the first column with a decimal number, note that you could use simply :sort n , as the help says: "With [n] ... sorting is done on the first decimal number in the line..." This doesn't apply to your case, but might to somebody elses.
look at :help :sort
When /{pattern}/ is specified and there is no [r] flag the text matched with {pattern} is skipped, so that you sort on what comes after the match. Instead of the slash any non-letter can be used.
:sort /^\(A \|The \)*/
This make sort of:
(ABBA)
The (Beatles)
(Duran Duran)
The (Rolling Stones)
(Styx)
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