23

I have several lines that I want to alphabetize. For example, say I have a bunch of vim set commands in a file:

set nowrap
set number
set expandtab
set hlsearch
set list

How would I alphabetize these 5 lines? The output would look like this:

set expandtab
set hlsearch
set list
set nowrap
set number
EvergreenTree
  • 1,788
  • 2
  • 16
  • 30
  • look at http://stackoverflow.com/questions/1355004/how-to-sort-numeric-and-literal-columns-in-vim. eg set the sort column by excluding the first word and space 2,5 sort /^\S\+\s\+/ but in this case just :1,5 sort would work as the first column is the sane – Steve Feb 06 '15 at 00:25

1 Answers1

36

The vim :sort command takes in a command line range, and allows you to use a regex to select what is sorted. You can also use the external sort command the same way, using :{range}!sort In my case, :1,5sort does what I want. More help on the :sort command is available in this vim help topic:

:help :sort

EvergreenTree
  • 1,788
  • 2
  • 16
  • 30