Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

vim sort based on given column

Tags:

vim

yaml

Suppose I have this section in my yaml file

hdkkhj50599: 1000000  
504sdaaf54: 00000054  
pppppp: 00005464

I want to sort these lines based on the values after colons.

None of the suggested solutions in stackoverflow worked for me.

How do I do it?

like image 816
smarber Avatar asked Sep 24 '26 16:09

smarber


1 Answers

Vim's internal :sort provides options for what you want: the n flag is for sorting decimal numbers (instead of alphabetially, though it wouldn't matter in your 0-padded example), a /.../ pattern is skipped at the beginning; we non-greedily match up to the first colon and whitespace:

:sort n/.\{-}: /
like image 60
Ingo Karkat Avatar answered Sep 27 '26 20:09

Ingo Karkat