Alphabetize lines of a given range in vim
Asked Answered
N

1

28

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
Nusku answered 6/2, 2015 at 0:15 Comment(1)
look at #1355504. 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 saneStormystorting
N
43

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

Nusku answered 6/2, 2015 at 0:25 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.