Selecting EDIT > Sort > Sort lines simply runs the sortmerg.vdm macro. This macro displays the sort dialog box which allows the user to enter all options and the column ranges for the primary and any secondary sort keys.
This user information is then used to build the appropriate Sort_Merge( ) command which performs the actual sorting.
In order to quickly sort large files, vEdit breaks files into small “chunks” which are sorted and then merged together. Assuming a large multi-megabyte file, vEdit copies the first ten 100-Kbyte chunks into ten (“extra”) buffers. Each chunk is then sorted; these ten chunks are then merged into a sorted temporary file with a size of about one megabyte. (This is called a “Level 0” merge.) The next ten 100-Kbyte chunks are then sorted and merged, and so on. When ten temporary files are written, they are merged into a 10-megabyte temporary file. (This is called a “Level 1” merge.) If there are ever ten 10-Megabyte temporary files, they are merged into a 100-megabyte temporary file. (This is called a “Level 2” merge.) Finally, if there are ever ten 100-mega-byte temporary files, they are merged into a 1000-megabyte temporary file. (This is called a “Level 3” merge.)
The process continues until the entire file / block has been sorted and merged into one temporary file. The status line gives a progress report and indicates the current merge level. The sorted temporary file is then read back into the original file’s buffer. This is indicated on the status line by the “Waiting for disk” message; this can take up to a minute per 100-megabytes on a typical 1-GHz computer.
The sorting is actually done using indexes and pointers into the ten sort/merge buffers. These indexes and pointers are also sorted and merged into temporary files. In all, 22 “extra” edit buffers are used in the sorting process.