Thursday, September 13, 2012

Re: How to ONLY sort part of a file and keep the format?

On Sep 13, 12:21 pm, Christian Brabandt <cbli...@256bit.org> wrote:
> Hi William!
>
> On Fr, 14 Sep 2012, William Fugh wrote:
>
> > Hi folks,
>
> > As the title. How to sort only the non-TAB-beginning line(s) of a TAB-Based
> > file like the below and keep the format? thanks!
> > #
> > --------------------------------------------------------------------------- ---
> > Origin:
> > #
> > --------------------------------------------------------------------------- ---
> > for openers
> > want out
> > a load of old cobblers
> > want for
> >         5. one
> >         6. two
> >         7. three
> > muck about
> > muck around
> >         20. one
> >         21. two
> >         22. three
> > bottom on
> >         24. one
> >         25. two
> >         26. three
> > lark around
> > lark about
> > darkred
> >         29. one
> >         30. two
> >         31. three
> > #
> > --------------------------------------------------------------------------- ---
> > Expect to see after sorting:
> > #
> > --------------------------------------------------------------------------- ---
> > a load of old cobblers
> > for openers
> > want for
> > want out
> >         5. one
> >         6. two
> >         7. three
> > muck about
> > muck around
> >         20. one
> >         21. two
> >         22. three
> > bottom on
> >         24. one
> >         25. two
> >         26. three
> > darkred
> > lark about
> > lark around
> >         29. one
> >         30. two
> >         31. three
> > #
> > --------------------------------------------------------------------------- ---
>
> I think, this will do:
> :v/^^I/.,/^^I/-sort
>
> where ^I is a literal tab.
>
> regards,
> Christian
> --

It also works using \t rather than the literal tab (^I):

:v/^\t/.,/^\t/-sort

Bill

--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

No comments: