[Help] How to ONLY sort part of a file and keep the format?

41 views
Skip to first unread message

William Fugh

unread,
Sep 13, 2012, 3:05:20 PM9/13/12
to vim...@googlegroups.com
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
# ------------------------------------------------------------------------------

BRs,
---------
William

Christian Brabandt

unread,
Sep 13, 2012, 3:21:41 PM9/13/12
to vim...@googlegroups.com
Hi William!
I think, this will do:
:v/^^I/.,/^^I/-sort

where ^I is a literal tab.


regards,
Christian
--

Bee

unread,
Sep 13, 2012, 3:31:37 PM9/13/12
to vim_use
It also works using \t rather than the literal tab (^I):

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

Bill

William Fugh

unread,
Sep 13, 2012, 4:15:53 PM9/13/12
to vim...@googlegroups.com
Amazing! thanks you guys very much! Got it.
-------------
William


--
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

360.gif

Bee

unread,
Sep 13, 2012, 7:15:22 PM9/13/12
to vim_use
> I think, this will do:
> :v/^^I/.,/^^I/-sort
> where ^I is a literal tab.
>
> It also works using \t rather than the literal tab (^I):
> :v/^\t/.,/^\t/-sort

Either way I get:
E16: Invalid range

But the sort works!

Bill

ping

unread,
Sep 13, 2012, 8:56:38 PM9/13/12
to vim...@googlegroups.com
interestingly, I tested it, this doesn't give the expected result.

//screen capture (that ^I is ctrl-v ctrl-i)
1 for openers
2 want out
3 a load of old cobblers
4 want for
5 5. one
6 6. two
7 7. three
8 muck about
9 muck around
10 20. one
11 21. two
12 22. three
13 bottom on
14 24. one
15 25. two
16 26. three
17 lark around
18 lark about
19 darkred
20 29. one
21 30. two
22 31. three
~
~
~
~
~
:v/^^I/.,/^^I/-sort

maybe we need that range-end (/^^I/) to be one line back?

William Fugh

unread,
Sep 14, 2012, 12:03:32 AM9/14/12
to vim...@googlegroups.com
On Fri, Sep 14, 2012 at 9:15 AM, Bee <fo...@calcentral.com> wrote:
> I think, this will do:
> :v/^^I/.,/^^I/-sort
> where ^I is a literal tab.
>
> It also works using  \t  rather than the literal tab (^I):
> :v/^\t/.,/^\t/-sort

Either way I get:
  E16: Invalid range
remove all empty lines. :-)
But the sort works!
 
Bill

William Fugh

unread,
Sep 14, 2012, 12:11:20 AM9/14/12
to vim...@googlegroups.com
try to press <TAB> key directly in command line. it does work fine. :-)

Christian Brabandt

unread,
Sep 14, 2012, 2:54:14 AM9/14/12
to vim...@googlegroups.com
Was there possibly a trailing empty line?

regards,
Christian

Christian Brabandt

unread,
Sep 14, 2012, 2:58:15 AM9/14/12
to vim...@googlegroups.com
I can't reproduce it and it works for me.

BTW: the range .,/^\t/- already backs up one line, see :h :range

regards,
Christian

Reply all
Reply to author
Forward
0 new messages