The sort command

When preparing lists it can be necessary that the list is in a given order. To sort a long list by hand can be quite time consuming, and a macro could do the job, but also it will be very slow. Therefore stedi has been equipped with a sort command. There are several options to make the command rather practical. The main command is the command O (for order, the s has been taken already by save and set) from the command line. If this is the whole command, the whole buffer is ordered in a lexicographic way. When this is done the first time there is usually a big scare: All the empty lines come first, so it is most likely that the user gets a blank screen in front of him. The more interesting things are usually near the end of the file. The various commands are:

O
The whole buffer is sorted on a line by line basis.
O#1,#2
The whole buffer is sorted, but from each line only the character ranges indicated by the given numbers (inclusive) are considered for determining which line comes first.
O:#1,#2
The whole buffer is sorted, but from each line only the column ranges indicated by the given numbers (inclusive) are considered for determining which line comes first.
OF#$[$char$]$
The whole buffer is sorted, but from each line only the the field indicated by the given number is considered when comparing two lines. Fields are separated by field separators. The default field separator is a comma, but if the user prefers a different field separator he can specify it after the number (so `char' is optional). For changing the order of the fields one should either use regular expression replacements, or make a more sophisticated macro.
OFN#$[$char$]$
This command is as the above, but before comparing the indicated fields stedi tries to interpret the fields numerically. If both fields are numbers in the range of $-2^{31}$ to $2^{31}-1$ the compare will be arithmetic, rather than lexicographic. (This allows one to sort lists of number without getting 10 to come before 9).
OR...
The R should be before the above options. It indicates that only the range from mark to cursor will be sorted. Only whole lines are considered, so the lines with the mark and the cursor are included entirely in the sort.
O<...
The less than sign should be the first character after the O. All other options may follow it. This indicates that the ordering will be backwards (largest comes first).
Closed folds are taken along in the sort as if they were a single line. No attempt is made to look inside the closed fold.

Example: We would like to sort the closed folds inside a buffer, but the folds have different characters for their first three characters (but no hash sign(#)). The command to give is then:

    OF3#
Here we indicate that the field separator is the hash sign, and that we are interested in the third field (the first field is made up by the first three characters, and the second field is the empty field between the two hash marks). If a field doesn't exist, as may be the case in lines that aren't closed fold lines, it is considered to be empty.



Subsections