> I'd like to sort all these lines together. I thought that
> would group all of these lines together and sort them
> relative to one another. But it's not so -- I think the 'g'
> command is treating them one by one, yes?
> Is there any way to do what I want?
Yes, it is treating each line individually. A solution might be
something like the following, assuming
0) the 1st character in the file isn't an asterisk (the first
line isn't one of interest)
1) you want the lines sorted at the top
You can do
:1ka | exec('g/^\*/m0') | 1,'a-1 !sort
:1ka | exec('g/^\*/t0') | 1,'a-1 !sort
depending on whether you want to move the lines to the top of the
file and sort them (the first one) or copy the lines to the top
of the file and sort them (the second one). It does tromp on the
"a" bookmark, but I couldn't find a nice way around that.
If you want to break it down, it marks the first line in the
file, then either copies or moves each matching line before the
first line. It now knows that the range from the first line,
through the line preceeding the mark we dropped are the lines you
want to sort, so it can then pass that range through your
system's sort command.
If you want them elsewhere, that may be another matter. Or you
can yank or delete all the germane lines into a register and then
manipulate them outside your document, with either
:let @a='' | g/^\*/d A
to delete those lines, or
:let @a='' | g/^\*/y A
You'll then have all the resulting lines in the "a" register, to
paste in another buffer and run the sort command over if you like:
you can then re-yank and drop the results where you please in
your original file.