Sorting a row (horizontally) in VIM

I know it is very easy to do sorting operations in vim via the build command sort

. But how to sort only one line and the text within that line horizontally?

eg. from this point (aaa ccc bbb)

to this(aaa bbb ccc)

I tried vi(:sort

but it didn't work for me. Any suggestions?

+3


source to share


2 answers


:s/\s\+/\r/g    " break the line into multiple ones
:'[,sort       " sort them
:,']j          " join them

      



+4


source


It's not trivial, but yes, you can always split a line into many lines, sort them and compose one line back.



This link might be helpful

+1


source







All Articles