Loading ...
Sorry, an error occurred while loading the content.

How to sort folding titles alphabetically?

Expand Messages
  • AMDx64BT
    I want to order alphabetically folded blocks of text according their title, but without changing the order of the lines inside the folded blocks. I want to
    Message 1 of 4 , Dec 2, 2010
    • 0 Attachment
      I want to order alphabetically folded blocks of text according their
      title, but without changing the order of the lines inside the folded
      blocks. I want to order the blocks, but not the lines inside.

      I am using a vim help file with the following syntax:

      vim:ft=help:fdm=expr
      vim:foldexpr=getline(v\:lnum-1)=~'-\\{80}'?'>2'\:getline(v\:lnum-1)=~'=
      \\{80}'?'>1'\:getline(v\:lnum)=~'=\\{80}'?'0'\:getline(v\:lnum)=~'-\
      \{80}'?'1'\:'='
      vim:foldtext=substitute(v\:folddashes.substitute(getline(v
      \:foldstart),'\\s*\\*.*',"",""),'^--','\ \ \ \ \ \ ','')

      Is there any way using vim (or external unix tools) to do this?

      --
      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
    • John Little
      Firstly, your foldexpr gave my vim indigestion, causing it to hang CPU bound when I attempted the following. I suggest temporarily setting fdm=manual if you
      Message 2 of 4 , Dec 2, 2010
      • 0 Attachment
        Firstly, your foldexpr gave my vim indigestion, causing it to hang CPU
        bound when I attempted the following. I suggest temporarily setting
        fdm=manual if you try it.

        If you can write a regex that matches the lines with your titles, you
        could

        :v/regex/s/$/xyzzy "mark the ends of non-title lines
        :g/xyzzy/-j! "join non-title lines with the one before it
        :sort
        :%s/xyzzy/\r/g "separate the lines out again
        :g/regex/-m . "move blank line to right place

        You might want to adjust the sort to suit your title lines; f.ex. I
        tested on eval.txt and its titles have a number, so I used :sort /\d\+
        \. /

        Beware, though, vim doesn't like really long lines. When I tested on
        eval.txt gvim's memory as reported by my system monitor jumped to 500
        MB, making my system swap furiously for a while. If your file has
        long blocks, longer than a few thousand lines vim might not cope.
        Maybe joining with the line before could be done in a way that isn't
        O(n^2), say joining them in pairs.

        If vim doesn't suit, you could use the same decorate, join, sort,
        split method with sed and sort I'm sure.

        Regards, John

        --
        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
      • John Little
        Further to my method above, it can work far faster if you do a ... while you re doing it. The syntax highlighting does not perform well with the very long
        Message 3 of 4 , Dec 3, 2010
        • 0 Attachment
          Further to my method above, it can work far faster if you do a

          :syntax off

          while you're doing it. The syntax highlighting does not perform well
          with the very long lines it uses.

          Regards, John

          --
          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
        • AMDx64BT
          Thanks John Little, good method. ... -- You received this message from the vim_use maillist. Do not top-post! Type your reply below the text you are replying
          Message 4 of 4 , Dec 5, 2010
          • 0 Attachment
            Thanks John Little, good method.

            On Dec 3, 9:24 pm, John Little <john.b.lit...@...> wrote:
            > Further to my method above, it can work far faster if you do a
            >
            > :syntax off
            >
            > while you're doing it.  The syntax highlighting does not perform well
            > with the very long lines it uses.
            >
            > Regards, John

            --
            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
          Your message has been successfully submitted and would be delivered to recipients shortly.