[Linux-disciples] Sorting lines matching a pattern

Adam Rosi-Kessel adam at rosi-kessel.org
Sun Jul 24 22:45:50 EDT 2005


Well, here is a command that will do it if you assume all of the * lines
are grouped together

:map _r gg/*<cr>VG?*<cr>\|!sort<cr>

(in other words, this will map _r to do that action)

It would be a little trickier if you wanted it to work where all of the *
lines are not in a clump.

You could thus have vim run that keystroke on your way out. As always,
there may be a more elegant way.

On Sun, Jul 24, 2005 at 10:12:34PM -0400, Stephen R Laniel wrote:
> The file corresponding to
> http://laniels.org/weblog/books/to_read_2005.html
> 
> looks like so:
> 
> To read, 2005
> meta-creation_date: 1/4/2005 03:28:21
> 
> * Fatsis, Stefan. "Word Freak"[book]
> * Abbey, Edward. "The Monkey Wrench Gang"[book]
> * Adams, Henry. "The Education of Henry Adams"[book]
> * Atwood, Margaret. "The Handmaid's Tale"[book]
> * Aurelius, Marcus, "Somethingorother"[book]
> [and so on]
> 
> Whenever I save that file, I'd like all the lines beginning
> with '*' to get sorted. I thought something like so in vim
> would do the trick:
> 
> :g/^\*/!sort
> 
> but it was not to be. I'm still not totally comfortable with
> the 'g[lobal]' command, for some reason, but I gather that
> the above command isn't lumping all of the '*' lines
> together and sorting them as one -- rather, it's maybe
> grabbing them one at a time and executing !sort on them
> individually.
> 
> Can someone suggest how I might do what I want in vim?
-- 
Adam Rosi-Kessel
http://adam.rosi-kessel.org
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : http://lists.bostoncoop.net/pipermail/linux-disciples/attachments/20050724/f6b73961/attachment.pgp


More information about the Linux-disciples mailing list