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

Fold according to keyword before fold mark?

Expand Messages
  • fkater@googlemail.com
    Hi all, Can anybody imagine a solution for this: I use a simple text file as my personal task planner. A line may contain a date, then a task (short title)
    Message 1 of 7 , Mar 1, 2010
      Hi all,

      Can anybody imagine a solution for this: I use a simple text file as
      my personal task planner. A line may contain a date, then a task
      (short title) which in turn has fold marks (simply {,} here) around
      the following lines describing the task. I wonder if I could configure
      vim to fold (hide) everything except for the "Task1" folds.
      Respectively, to fold everything but the "Task2" folds and so on.

      This is the structure I use:

      02/01/2010
      Task1{
      ...
      }
      Task2{
      ...
      }

      02/02/2010
      Task1{ // again the same Task1 continued
      ...
      }
      Task3{
      ...
      }

      Thank You
      Felix

      --
      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
    • fkater@googlemail.com
      ... Very impressive -- it folds/unfolds to a given fold depth, however, the main aspect I am looking for is not covered by VimOutliner. I look for a way to
      Message 2 of 7 , Mar 1, 2010
        > Have you checked vimoutliner?
        >
        > http://www.vimoutliner.org/

        Very impressive -- it folds/unfolds to a given fold depth, however,
        the main aspect I am looking for is not covered by VimOutliner.

        I look for a way to fold/unfold ALL folds belonging to the same "type"
        of fold (indicated e.g. by a leading keyword before the fold mark), so
        see only those folds of interest.

        Felix

        --
        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
      • Adam Duck
        ... I think I have the thing you re looking for. I think it s from a vimtip or something: #v+ Causes all comment folds to be opened and closed using z[
        Message 3 of 7 , Mar 1, 2010
          On 01.03.2010 16:29, fkater@... wrote:
          >> Have you checked vimoutliner?
          >>
          >> http://www.vimoutliner.org/
          >>
          > Very impressive -- it folds/unfolds to a given fold depth, however,
          > the main aspect I am looking for is not covered by VimOutliner.
          >
          > I look for a way to fold/unfold ALL folds belonging to the same "type"
          > of fold (indicated e.g. by a leading keyword before the fold mark), so
          > see only those folds of interest.
          >
          > Felix
          >
          >
          I think I have the thing you're looking for. I think it's from a vimtip
          or something:

          #v+

          "
          " Causes all comment folds to be opened and closed using z[ and z]
          " respectively.
          "
          " Causes all block folds to be opened and closed using z{ and z}
          respectively.
          "

          function FoldOnlyMatching(re, op)
          mark Z
          keepjumps normal gg
          let s:lastline = -1
          while s:lastline != line('.')
          if match(getline(line('.')), a:re) != -1
          exec 'normal ' . a:op
          endif
          let s:lastline = line('.')
          keepjumps normal zj
          endwhile
          keepjumps normal 'Z
          unlet s:lastline
          endfunction

          nnoremap <silent> z[ :call FoldOnlyMatching('/[*][*]', 'zo')<CR>
          nnoremap <silent> z] :call FoldOnlyMatching('/[*][*]', 'zc')<CR>
          nnoremap <silent> z{ :call FoldOnlyMatching('[ \t]*{', 'zo')<CR>
          nnoremap <silent> z} :call FoldOnlyMatching('[ \t]*{', 'zc')<CR>

          #v-

          I've never tried ":call FoldOnlyMatching('Task1{', 'zo')<CR>" or so, but
          it should work.

          cu, Adam.

          --
          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
        • Adam Duck
          ... I think I have the thing you re looking for. I think it s from a vimtip or something: #v+ Causes all comment folds to be opened and closed using z[
          Message 4 of 7 , Mar 1, 2010
            On 01.03.2010 16:29, fkater@... wrote:
            >> Have you checked vimoutliner?
            >>
            >> http://www.vimoutliner.org/
            >>
            > Very impressive -- it folds/unfolds to a given fold depth, however,
            > the main aspect I am looking for is not covered by VimOutliner.
            >
            > I look for a way to fold/unfold ALL folds belonging to the same "type"
            > of fold (indicated e.g. by a leading keyword before the fold mark), so
            > see only those folds of interest.
            >
            > Felix
            >
            >
            I think I have the thing you're looking for. I think it's from a vimtip
            or something:

            #v+

            "
            " Causes all comment folds to be opened and closed using z[ and z]
            " respectively.
            "
            " Causes all block folds to be opened and closed using z{ and z}
            respectively.
            "

            function FoldOnlyMatching(re, op)
            mark Z
            keepjumps normal gg
            let s:lastline = -1
            while s:lastline != line('.')
            if match(getline(line('.')), a:re) != -1
            exec 'normal ' . a:op
            endif
            let s:lastline = line('.')
            keepjumps normal zj
            endwhile
            keepjumps normal 'Z
            unlet s:lastline
            endfunction

            nnoremap <silent> z[ :call FoldOnlyMatching('/[*][*]', 'zo')<CR>
            nnoremap <silent> z] :call FoldOnlyMatching('/[*][*]', 'zc')<CR>
            nnoremap <silent> z{ :call FoldOnlyMatching('[ \t]*{', 'zo')<CR>
            nnoremap <silent> z} :call FoldOnlyMatching('[ \t]*{', 'zc')<CR>

            #v-

            I've never tried ":call FoldOnlyMatching('Task1{', 'zo')<CR>" or so, but
            it should work.

            cu, Adam.

            --
            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
          • Christian Brabandt
            Hi! ... Does that work: #v+ fu! MyFL(lnum) if getline(a:lnum) =~ {$ return a1 elseif getline(a:lnum) =~ }$ return s1 elseif getline(a:lnum) =~
            Message 5 of 7 , Mar 1, 2010
              Hi!

              On Mo, 01 Mär 2010, fkater@... wrote:

              > I look for a way to fold/unfold ALL folds belonging to the same "type"
              > of fold (indicated e.g. by a leading keyword before the fold mark), so
              > see only those folds of interest.

              Does that work:
              #v+
              fu! MyFL(lnum)
              if getline(a:lnum) =~ '{$'
              return 'a1'
              elseif getline(a:lnum) =~ '}$'
              return 's1'
              elseif getline(a:lnum) =~ '^[0-9/]\+$'
              return '1'
              elseif getline(a:lnum) =~ '^$'
              return '0'
              else
              return '='
              endif
              endfu

              set fdm=expr foldexpr=MyFL(v:lnum)
              #v-

              regards,
              Christian
              --
              :wq

              --
              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
            • fkater@googlemail.com
              Thanks so far -- as I am not too much into vim scripting it will take a little time for me to test it. But it looks very much what I d love to see working!
              Message 6 of 7 , Mar 1, 2010
                Thanks so far -- as I am not too much into vim scripting it will take
                a little time for me to test it.
                But it looks very much what I'd love to see working!
                Thank You so far
                Felix

                On Mar 1, 6:05 pm, Christian Brabandt <cbli...@...> wrote:
                > Hi!
                >
                > On Mo, 01 M r 2010, fka...@... wrote:
                >
                > > I look for a way to fold/unfold ALL folds belonging to the same "type"
                > > of fold (indicated e.g. by a leading keyword before the fold mark), so
                > > see only those folds of interest.
                >
                > Does that work:
                > #v+
                > fu! MyFL(lnum)
                >     if getline(a:lnum) =~ '{$'
                >         return 'a1'
                >     elseif getline(a:lnum) =~ '}$'
                >         return 's1'
                >     elseif getline(a:lnum) =~ '^[0-9/]\+$'
                >         return '1'
                >     elseif getline(a:lnum) =~ '^$'
                >         return '0'
                >     else
                >         return '='
                >     endif
                > endfu
                >
                > set fdm=expr foldexpr=MyFL(v:lnum)
                > #v-
                >
                > regards,
                > Christian
                > --
                > :wq

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