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

hiding lines

Expand Messages
  • Derek Wyatt
    Hi folks, I ve got some CC source files that were generated by rational rose and they annoy me to death. There are a ton of lines that look like this in it:
    Message 1 of 26 , Sep 20, 2002
    • 0 Attachment
      Hi folks,

      I've got some CC source files that were generated by rational rose and they
      annoy me to death. There are a ton of lines that look like this in it:

      //## here's some annoying text
      here's a variable
      //## here's some more annoying text


      I can't delete the lines from the file but i want them out of the way. Is
      there some way to hide these lines in the file so that they always get
      written but i only see them when i ask for them?

      Cheers,
      Derek

      --
      -----------------------------------------------------------
      Derek Quinn Wyatt | Phone: (905) 886-7818 ext. 2313
      Syndesis Engineering | Fax: (905) 886-9076
      Toronto, Ontario, CAN | Email: wyatt@...
      -----------------------------------------------------------
      "Information about package holidays on the FrogStar are
      available in the leaflet, 'Sun, Sand and Suffering on the
      most totally evil place in the galaxy'"
    • Colin Keith
      Set a highlighting range that highlights it in black (or whatever your background colour is) ? ... This will make it look like a big empty block though, so
      Message 2 of 26 , Sep 20, 2002
      • 0 Attachment
        Set a highlighting range that highlights it in black (or whatever your
        background colour is) ?


        :syn match Blackout +^//##.*$\n^.*$\n^//##.*$+
        :hi Blackout ctermbg=Black ctermfg=Black guifg=Black guibg=Black

        This will make it look like a big empty block though, so maybe folding
        would be useful?



        On Fri, Sep 20, 2002 at 02:34:52PM -0400, Derek Wyatt wrote:
        > From: Derek Wyatt <wyatt@...>
        > To: vim@...
        > Date: Fri, 20 Sep 2002 14:34:52 -0400
        > Subject: hiding lines
        >
        > Hi folks,
        >
        > I've got some CC source files that were generated by rational rose and they
        > annoy me to death. There are a ton of lines that look like this in it:
        >
        > //## here's some annoying text
        > here's a variable
        > //## here's some more annoying text
        >
        >
        > I can't delete the lines from the file but i want them out of the way. Is
        > there some way to hide these lines in the file so that they always get
        > written but i only see them when i ask for them?
        >
        > Cheers,
        > Derek
        >
        > --
        > -----------------------------------------------------------
        > Derek Quinn Wyatt | Phone: (905) 886-7818 ext. 2313
        > Syndesis Engineering | Fax: (905) 886-9076
        > Toronto, Ontario, CAN | Email: wyatt@...
        > -----------------------------------------------------------
        > "Information about package holidays on the FrogStar are
        > available in the leaflet, 'Sun, Sand and Suffering on the
        > most totally evil place in the galaxy'"
        >
        >

        --
        First Name: Colin, one 'ell', not two. Increase your font size if you
        thought it had two. Pronounced: Col-in, not Cooo-lin
        Surname: Keith. Yes surname, not forename. Its the name of a Scottish clan
        that once owned half of Scotland...
      • Gary Holloway
        One way, if you are using syntax highlighting and don t mind having blank lines (probably not exactly what you want), would be to use a syntax group that
        Message 3 of 26 , Sep 20, 2002
        • 0 Attachment
          One way, if you are using syntax highlighting and don't mind having blank
          lines (probably not exactly what you want), would be to use a syntax group that
          matches the line, and then use a foreground color the same as the background
          color.

          e.g.,

          syntax match ccAnnoying +^//##.*$+

          Then use:

          hi link ccAnnoying Ignore

          to "hide" them, and use

          hi link ccAnnoying NONE

          to "restore" them.
          (Of course the highlight commands could be tied to a mapping, or such.)

          -gary

          / FROM: Derek Wyatt <wyatt@...>, Sep 20 14:34 2002
          | ABOUT: hiding lines
          |
          | Hi folks,
          |
          | I've got some CC source files that were generated by rational rose and they
          | annoy me to death. There are a ton of lines that look like this in it:
          |
          | //## here's some annoying text
          | here's a variable
          | //## here's some more annoying text
          |
          | I can't delete the lines from the file but i want them out of the way. Is
          | there some way to hide these lines in the file so that they always get
          | written but i only see them when i ask for them?
          |
          | Cheers,
          | Derek
          |
          | --
          | -----------------------------------------------------------
          | Derek Quinn Wyatt | Phone: (905) 886-7818 ext. 2313
          | Syndesis Engineering | Fax: (905) 886-9076
          | Toronto, Ontario, CAN | Email: wyatt@...
          | -----------------------------------------------------------
          | "Information about package holidays on the FrogStar are
          | available in the leaflet, 'Sun, Sand and Suffering on the
          | most totally evil place in the galaxy'"
          |
          \ END: Derek Wyatt
        • Derek Wyatt
          Hmmm... two suggestions for hilighting. I didn t think of that and it s not a bad idea. I ll leave it as a can t think of anything else idea. The problem
          Message 4 of 26 , Sep 20, 2002
          • 0 Attachment
            Hmmm... two suggestions for hilighting.

            I didn't think of that and it's not a bad idea. I'll leave it as a "can't
            think of anything else" idea.

            The problem with it that i can see is that i hate extraneous blank lines
            almost as much as the ugly rational rose lines :) I wouldn't be able to
            see which ones to delete and which ones to keep unless i was always
            hilighting on and off (easy to do with a mapping... true).

            But good idea. If it turns out that VIM doesn't have a "better" way then
            i'll do this.

            What i would really like to have a specific "view" into the file. Kinda
            like, "let me work on this file, viewing it through this filter" where the
            filter is something like ^//##.*$ or whatever i want. Then VIM can behave
            as though the lines are there, and a 'j' movement over them would simply
            result in 2j or whatever the pattern matched.

            I've looked through what i can find and i don't think it's there... if it's
            not then maybe i have my first real request of the VIM developers after
            over 2 years of working with it. I've never been left wanting before :)

            Thanks a lot,
            Derek

            On Fri, Sep 20, 2002 at 07:58:21PM +0100, Colin Keith wrote:
            |
            | Set a highlighting range that highlights it in black (or whatever your
            | background colour is) ?
            |
            |
            | :syn match Blackout +^//##.*$\n^.*$\n^//##.*$+
            | :hi Blackout ctermbg=Black ctermfg=Black guifg=Black guibg=Black
            |
            | This will make it look like a big empty block though, so maybe folding
            | would be useful?
            |
            |
            |
            | On Fri, Sep 20, 2002 at 02:34:52PM -0400, Derek Wyatt wrote:
            | > From: Derek Wyatt <wyatt@...>
            | > To: vim@...
            | > Date: Fri, 20 Sep 2002 14:34:52 -0400
            | > Subject: hiding lines
            | >
            | > Hi folks,
            | >
            | > I've got some CC source files that were generated by rational rose and they
            | > annoy me to death. There are a ton of lines that look like this in it:
            | >
            | > //## here's some annoying text
            | > here's a variable
            | > //## here's some more annoying text
            | >
            | >
            | > I can't delete the lines from the file but i want them out of the way. Is
            | > there some way to hide these lines in the file so that they always get
            | > written but i only see them when i ask for them?
            | >
            | > Cheers,
            | > Derek
            | >
            | > --
            | > -----------------------------------------------------------
            | > Derek Quinn Wyatt | Phone: (905) 886-7818 ext. 2313
            | > Syndesis Engineering | Fax: (905) 886-9076
            | > Toronto, Ontario, CAN | Email: wyatt@...
            | > -----------------------------------------------------------
            | > "Information about package holidays on the FrogStar are
            | > available in the leaflet, 'Sun, Sand and Suffering on the
            | > most totally evil place in the galaxy'"
            | >
            | >
            |
            | --
            | First Name: Colin, one 'ell', not two. Increase your font size if you
            | thought it had two. Pronounced: Col-in, not Cooo-lin
            | Surname: Keith. Yes surname, not forename. Its the name of a Scottish clan
            | that once owned half of Scotland...

            --
            -----------------------------------------------------------
            Derek Quinn Wyatt | Phone: (905) 886-7818 ext. 2313
            Syndesis Engineering | Fax: (905) 886-9076
            Toronto, Ontario, CAN | Email: wyatt@...
            -----------------------------------------------------------
            "Information about package holidays on the FrogStar are
            available in the leaflet, 'Sun, Sand and Suffering on the
            most totally evil place in the galaxy'"
          • Derek Wyatt
            ... Oh, i forgot to mention, folding is no good since i m only dealing with one line comments... one line comments replaced by one line folds is no less
            Message 5 of 26 , Sep 20, 2002
            • 0 Attachment
              | This will make it look like a big empty block though, so maybe folding
              | would be useful?

              Oh, i forgot to mention, folding is no good since i'm only dealing with one
              line comments... one line comments replaced by one line folds is no less
              annoying. I should have been more clear about how many lines were
              involved. Sorry 'bout that.

              --
              -----------------------------------------------------------
              Derek Quinn Wyatt | Phone: (905) 886-7818 ext. 2313
              Syndesis Engineering | Fax: (905) 886-9076
              Toronto, Ontario, CAN | Email: wyatt@...
              -----------------------------------------------------------
              "Information about package holidays on the FrogStar are
              available in the leaflet, 'Sun, Sand and Suffering on the
              most totally evil place in the galaxy'"
            • Colin Keith
              ... I think the answer is that you can t do it in the way you re hoping. Vim doesn t have the ability to just not display lines but keep them in memory (at
              Message 6 of 26 , Sep 20, 2002
              • 0 Attachment
                On Fri, Sep 20, 2002 at 03:25:29PM -0400, Derek Wyatt wrote:
                > Oh, i forgot to mention, folding is no good since i'm only dealing with one
                > line comments... one line comments replaced by one line folds is no less
                > annoying. I should have been more clear about how many lines were
                > involved. Sorry 'bout that.

                :)

                I think the answer is that you can't do it in the way you're hoping. Vim
                doesn't have the ability to just not display lines but keep them in memory
                (at least I've never seen any reference to anything like this). In
                otherwords you can't have:


                1 //## test
                2 test
                3 //## test
                4 int main( .... )


                And when you open it see just:

                4 int main( .... )


                You can either obscure them or remove them. If you don't want them back
                then removing them is easy. If you do... well you may be able to strip them
                out and add them back, but I can't think of an easy way to do that.

                Stripping them is easy btw:

                au BufRead *.c :%g%^//##%.,+2d

                or if you want the variable (I can't remmeber if you did)

                au BufRead *.c :%g%^//##%d|+1d


                (I also can't remember if you said it was .c or .cpp or something)


                You *might* be able to swing something like:

                au BufRead *.c call StripComments()
                au BufWrite *.c call RestoreComments()


                function! StripComments()
                call delete('comments.tags')

                while search('^//## ', 'W')
                :.,+2write! >> comments.tags
                :d|+1d|+1
                endwhile
                :write
                endfunction

                " I'm having some problems with the search() in here though :(
                function! RestoreComments()
                :split comments.tags
                let ll = line('$')

                while(line('.') < ll)
                :silent .,+2y a
                :silent +1y b
                :let g:a = @a
                :let g:b = @b
                :wincmd j
                :let @a = g:a
                :let @b = g:b

                " look for this tag and replace if found.
                if search(@b, 'W')
                :d
                :put a
                else
                echoerr "Error finding tag: "+ g:b
                endif

                :wincmd k
                :+3
                endwhile

                " call delete('comments.tags');

                endfunction
              • Derek Wyatt
                Whoah... if it doesn t do it it s at least a great start. I hate the fact that i can t try it out yet, but i m blasting out the door and won t be able to check
                Message 7 of 26 , Sep 20, 2002
                • 0 Attachment
                  Whoah... if it doesn't do it it's at least a great start.

                  I hate the fact that i can't try it out yet, but i'm blasting out the door
                  and won't be able to check it till monday! I should have asked sooner :)

                  I'll get back to you.

                  Regs,
                  D

                  On Fri, Sep 20, 2002 at 09:44:58PM +0100, Colin Keith wrote:
                  | On Fri, Sep 20, 2002 at 03:25:29PM -0400, Derek Wyatt wrote:
                  | > Oh, i forgot to mention, folding is no good since i'm only dealing with one
                  | > line comments... one line comments replaced by one line folds is no less
                  | > annoying. I should have been more clear about how many lines were
                  | > involved. Sorry 'bout that.
                  |
                  | :)
                  |
                  | I think the answer is that you can't do it in the way you're hoping. Vim
                  | doesn't have the ability to just not display lines but keep them in memory
                  | (at least I've never seen any reference to anything like this). In
                  | otherwords you can't have:
                  |
                  |
                  | 1 //## test
                  | 2 test
                  | 3 //## test
                  | 4 int main( .... )
                  |
                  |
                  | And when you open it see just:
                  |
                  | 4 int main( .... )
                  |
                  |
                  | You can either obscure them or remove them. If you don't want them back
                  | then removing them is easy. If you do... well you may be able to strip them
                  | out and add them back, but I can't think of an easy way to do that.
                  |
                  | Stripping them is easy btw:
                  |
                  | au BufRead *.c :%g%^//##%.,+2d
                  |
                  | or if you want the variable (I can't remmeber if you did)
                  |
                  | au BufRead *.c :%g%^//##%d|+1d
                  |
                  |
                  | (I also can't remember if you said it was .c or .cpp or something)
                  |
                  |
                  | You *might* be able to swing something like:
                  |
                  | au BufRead *.c call StripComments()
                  | au BufWrite *.c call RestoreComments()
                  |
                  |
                  | function! StripComments()
                  | call delete('comments.tags')
                  |
                  | while search('^//## ', 'W')
                  | :.,+2write! >> comments.tags
                  | :d|+1d|+1
                  | endwhile
                  | :write
                  | endfunction
                  |
                  | " I'm having some problems with the search() in here though :(
                  | function! RestoreComments()
                  | :split comments.tags
                  | let ll = line('$')
                  |
                  | while(line('.') < ll)
                  | :silent .,+2y a
                  | :silent +1y b
                  | :let g:a = @a
                  | :let g:b = @b
                  | :wincmd j
                  | :let @a = g:a
                  | :let @b = g:b
                  |
                  | " look for this tag and replace if found.
                  | if search(@b, 'W')
                  | :d
                  | :put a
                  | else
                  | echoerr "Error finding tag: "+ g:b
                  | endif
                  |
                  | :wincmd k
                  | :+3
                  | endwhile
                  |
                  | " call delete('comments.tags');
                  |
                  | endfunction

                  --
                  -----------------------------------------------------------
                  Derek Quinn Wyatt | Phone: (905) 886-7818 ext. 2313
                  Syndesis Engineering | Fax: (905) 886-9076
                  Toronto, Ontario, CAN | Email: wyatt@...
                  -----------------------------------------------------------
                  "Information about package holidays on the FrogStar are
                  available in the leaflet, 'Sun, Sand and Suffering on the
                  most totally evil place in the galaxy'"
                • Alan G Isaac
                  ... I think you are talking about slicing. THE has it. People who use slicing seem to love it. I am not sure why it has advantages over :g and :v, but maybe
                  Message 8 of 26 , Sep 20, 2002
                  • 0 Attachment
                    On Fri, 20 Sep 2002 15:24:07 -0400 Derek Wyatt <wyatt@...> wrote:
                    > What i would really like to have a specific "view" into the file. Kinda
                    > like, "let me work on this file, viewing it through this filter" where the
                    > filter is something like ^//##.*$ or whatever i want. Then VIM can behave
                    > as though the lines are there, and a 'j' movement over them would simply
                    > result in 2j or whatever the pattern matched.


                    I think you are talking about slicing.
                    THE has it. People who use slicing seem to love it.
                    I am not sure why it has advantages over :g and :v,
                    but maybe someone will explain.

                    Alan Isaac

                    PS For a description of slicing see the discussion
                    of the 'all' command at the bottom of
                    http://www.uic.edu/depts/accc/software/the/theintro.html
                  • Derek Wyatt
                    Thanks again Colin. A little birdie told me that the conceal patch existed and, although it s not mainstream, i decided to give it a whirl. It doesn t do
                    Message 9 of 26 , Sep 23, 2002
                    • 0 Attachment
                      Thanks again Colin.

                      A little birdie told me that the "conceal" patch existed and, although it's
                      not mainstream, i decided to give it a whirl. It doesn't do exactly what i
                      need but it does a great job nonetheless. And it saves me the time of
                      coming up with my own solution. They actually make me code here... i can't
                      just play with VIM all day... a brutal shame.

                      Regards,
                      Derek

                      On Fri, Sep 20, 2002 at 09:44:58PM +0100, Colin Keith wrote:
                      | On Fri, Sep 20, 2002 at 03:25:29PM -0400, Derek Wyatt wrote:
                      | > Oh, i forgot to mention, folding is no good since i'm only dealing with one
                      | > line comments... one line comments replaced by one line folds is no less
                      | > annoying. I should have been more clear about how many lines were
                      | > involved. Sorry 'bout that.
                      |
                      | :)
                      |
                      | I think the answer is that you can't do it in the way you're hoping. Vim
                      | doesn't have the ability to just not display lines but keep them in memory
                      | (at least I've never seen any reference to anything like this). In
                      | otherwords you can't have:
                      |
                      |
                      | 1 //## test
                      | 2 test
                      | 3 //## test
                      | 4 int main( .... )
                      |
                      |
                      | And when you open it see just:
                      |
                      | 4 int main( .... )
                      |
                      |
                      | You can either obscure them or remove them. If you don't want them back
                      | then removing them is easy. If you do... well you may be able to strip them
                      | out and add them back, but I can't think of an easy way to do that.
                      |
                      | Stripping them is easy btw:
                      |
                      | au BufRead *.c :%g%^//##%.,+2d
                      |
                      | or if you want the variable (I can't remmeber if you did)
                      |
                      | au BufRead *.c :%g%^//##%d|+1d
                      |
                      |
                      | (I also can't remember if you said it was .c or .cpp or something)
                      |
                      |
                      | You *might* be able to swing something like:
                      |
                      | au BufRead *.c call StripComments()
                      | au BufWrite *.c call RestoreComments()
                      |
                      |
                      | function! StripComments()
                      | call delete('comments.tags')
                      |
                      | while search('^//## ', 'W')
                      | :.,+2write! >> comments.tags
                      | :d|+1d|+1
                      | endwhile
                      | :write
                      | endfunction
                      |
                      | " I'm having some problems with the search() in here though :(
                      | function! RestoreComments()
                      | :split comments.tags
                      | let ll = line('$')
                      |
                      | while(line('.') < ll)
                      | :silent .,+2y a
                      | :silent +1y b
                      | :let g:a = @a
                      | :let g:b = @b
                      | :wincmd j
                      | :let @a = g:a
                      | :let @b = g:b
                      |
                      | " look for this tag and replace if found.
                      | if search(@b, 'W')
                      | :d
                      | :put a
                      | else
                      | echoerr "Error finding tag: "+ g:b
                      | endif
                      |
                      | :wincmd k
                      | :+3
                      | endwhile
                      |
                      | " call delete('comments.tags');
                      |
                      | endfunction

                      --
                      -----------------------------------------------------------
                      Derek Quinn Wyatt | Phone: (905) 886-7818 ext. 2313
                      Syndesis Engineering | Fax: (905) 886-9076
                      Toronto, Ontario, CAN | Email: wyatt@...
                      -----------------------------------------------------------
                      "Information about package holidays on the FrogStar are
                      available in the leaflet, 'Sun, Sand and Suffering on the
                      most totally evil place in the galaxy'"
                    • Bill Pursell
                      Is it possible to completely hide lines? Something stronger than merely folding. In particular, I d like to be able to display the buffer with all lines
                      Message 10 of 26 , May 1, 2006
                      • 0 Attachment
                        Is it possible to completely hide lines? Something stronger than merely
                        folding. In particular, I'd like to be able to display the buffer with
                        all lines containing "assert" hidden, or to hide lines between and
                        including #ifdef/#endif pairs. Can that be done?
                      • Yakov Lerner
                        ... Piping the buffer text into temp. buffer through some sort of grep -v. Yakov
                        Message 11 of 26 , May 1, 2006
                        • 0 Attachment
                          On 5/1/06, Bill Pursell <bill.pursell@...> wrote:
                          >
                          > Is it possible to completely hide lines? Something stronger than merely
                          > folding. In particular, I'd like to be able to display the buffer with
                          > all lines containing "assert" hidden, or to hide lines between and
                          > including #ifdef/#endif pairs. Can that be done?

                          Piping the buffer text into temp. buffer through some sort
                          of grep -v.

                          Yakov
                        • cga2000
                          ... could you be a little more specific - or provide a short example.. been looking for something like this myself for some time.. thanks, cga
                          Message 12 of 26 , May 1, 2006
                          • 0 Attachment
                            Thus spake Yakov Lerner on Mon, May 01, 2006 at 10:06:57PM +0300 or thereabouts: <iler.ml@...> [2006-05-01 17:25]:
                            > On 5/1/06, Bill Pursell <bill.pursell@...> wrote:
                            > >
                            > >Is it possible to completely hide lines? Something stronger than merely
                            > >folding. In particular, I'd like to be able to display the buffer with
                            > >all lines containing "assert" hidden, or to hide lines between and
                            > >including #ifdef/#endif pairs. Can that be done?
                            >
                            > Piping the buffer text into temp. buffer through some sort
                            > of grep -v.
                            >

                            could you be a little more specific - or provide a short example.. been
                            looking for something like this myself for some time..


                            thanks,

                            cga
                          • Gary Johnson
                            ... I can t think of anything grep -v can do in this situation that v/ /d can t, so here s one way to do this: gg aYG ... ap ... HTH,
                            Message 13 of 26 , May 1, 2006
                            • 0 Attachment
                              On 2006-05-01, cga2000 <cga2000@...> wrote:
                              > Thus spake Yakov Lerner on Mon, May 01, 2006 at 10:06:57PM +0300 or thereabouts: <iler.ml@...> [2006-05-01 17:25]:
                              > > On 5/1/06, Bill Pursell <bill.pursell@...> wrote:
                              > > >
                              > > >Is it possible to completely hide lines? Something stronger than merely
                              > > >folding. In particular, I'd like to be able to display the buffer with
                              > > >all lines containing "assert" hidden, or to hide lines between and
                              > > >including #ifdef/#endif pairs. Can that be done?
                              > >
                              > > Piping the buffer text into temp. buffer through some sort
                              > > of grep -v.
                              > >
                              >
                              > could you be a little more specific - or provide a short example.. been
                              > looking for something like this myself for some time..

                              I can't think of anything 'grep -v <pattern>' can do in this
                              situation that 'v/<patter>/d' can't, so here's one way to do this:

                              gg"aYG
                              :new
                              "ap
                              :1d
                              :v/assert/d

                              HTH,
                              Gary

                              --
                              Gary Johnson | Agilent Technologies
                              garyjohn@... | Wireless Division
                              | Spokane, Washington, USA
                            • cga2000
                              ... Thanks, Gary..
                              Message 14 of 26 , May 1, 2006
                              • 0 Attachment
                                Thus spake Gary Johnson on Mon, May 01, 2006 at 02:52:21PM -0700 or thereabouts: <garyjohn@...> [2006-05-01 19:31]:
                                > On 2006-05-01, cga2000 <cga2000@...> wrote:
                                > > Thus spake Yakov Lerner on Mon, May 01, 2006 at 10:06:57PM +0300 or thereabouts: <iler.ml@...> [2006-05-01 17:25]:
                                > > > On 5/1/06, Bill Pursell <bill.pursell@...> wrote:
                                > > > >
                                > > > >Is it possible to completely hide lines? Something stronger than merely
                                > > > >folding. In particular, I'd like to be able to display the buffer with
                                > > > >all lines containing "assert" hidden, or to hide lines between and
                                > > > >including #ifdef/#endif pairs. Can that be done?
                                > > >
                                > > > Piping the buffer text into temp. buffer through some sort
                                > > > of grep -v.
                                > > >
                                > >
                                > > could you be a little more specific - or provide a short example.. been
                                > > looking for something like this myself for some time..
                                >
                                > I can't think of anything 'grep -v <pattern>' can do in this
                                > situation that 'v/<patter>/d' can't, so here's one way to do this:
                                >
                                > gg"aYG
                                > :new
                                > "ap
                                > :1d
                                > :v/assert/d
                                >
                                > HTH,
                                > Gary

                                Thanks, Gary..

                                :v (and :g) made my day..!

                                >
                                > --
                                > Gary Johnson | Agilent Technologies
                                > garyjohn@... | Wireless Division
                                > | Spokane, Washington, USA
                              • Yakov Lerner
                                ... Yes, grep -v in vim is easy. But how do you remove #ifdef blocks ? I mentioned piping because there is ready utility, unifdef , that removes some or all
                                Message 15 of 26 , May 1, 2006
                                • 0 Attachment
                                  On 5/2/06, Gary Johnson <garyjohn@...> wrote:
                                  > > Thus spake Yakov Lerner on Mon, May 01, 2006 at 10:06:57PM +0300 or thereabouts: <iler.ml@...> [2006-05-01 17:25]:
                                  > > > On 5/1/06, Bill Pursell <bill.pursell@...> wrote:
                                  > > > >Is it possible to completely hide lines? Something stronger than merely
                                  > > > >folding. In particular, I'd like to be able to display the buffer with
                                  > > > >all lines containing "assert" hidden, or to hide lines between and
                                  > > > >including #ifdef/#endif pairs. Can that be done?
                                  > > >
                                  > > > Piping the buffer text into temp. buffer through some sort
                                  > > > of grep -v.
                                  > I can't think of anything 'grep -v <pattern>' can do in this
                                  > situation that 'v/<patter>/d' can't, so here's one way to do this:

                                  Yes, 'grep -v' in vim is easy. But how do you remove #ifdef blocks ?
                                  I mentioned piping because there is ready utility, 'unifdef',
                                  that removes some or all of #if blocks.

                                  Yakov

                                  > gg"aYG
                                  > :new
                                  > "ap
                                  > :1d
                                  > :v/assert/d
                                • Suresh Govindachar
                                  ... where the *s are multi-line and non-greedy, or maybe I should say the *s are non-greedy and the . is multi-line? (I haven t actually tried, but I am
                                  Message 16 of 26 , May 1, 2006
                                  • 0 Attachment
                                    Yakov Lerner wondered:

                                    > But how do you remove #ifdef blocks? I mentioned piping because
                                    > there is ready utility, 'unifdef', that removes some or all of
                                    > #if blocks.

                                    Isn't there a way to do a multi-line substitution:

                                    :%s/^\s*#ifdef .*^\s*#endif//

                                    where the *s are multi-line and non-greedy, or maybe I should
                                    say the *s are non-greedy and the . is multi-line? (I haven't
                                    actually tried, but I am confident I can do it in perl.)

                                    --Suresh
                                  • Yakov Lerner
                                    ... What if #if/#endif blocks are nested ? Yakov
                                    Message 17 of 26 , May 1, 2006
                                    • 0 Attachment
                                      On 5/2/06, Suresh Govindachar <sgovindachar@...> wrote:
                                      >
                                      > Yakov Lerner wondered:
                                      >
                                      > > But how do you remove #ifdef blocks? I mentioned piping because
                                      > > there is ready utility, 'unifdef', that removes some or all of
                                      > > #if blocks.
                                      >
                                      > Isn't there a way to do a multi-line substitution:
                                      >
                                      > :%s/^\s*#ifdef .*^\s*#endif//
                                      >
                                      > where the *s are multi-line and non-greedy, or maybe I should
                                      > say the *s are non-greedy and the . is multi-line? (I haven't
                                      > actually tried, but I am confident I can do it in perl.)

                                      What if #if/#endif blocks are nested ?

                                      Yakov
                                    • Tim Chase
                                      ... Yakov is correct, that nested #if/#endif blocks would cause trouble. My first thought at a [100% untested] solution would be something like ... which would
                                      Message 18 of 26 , May 1, 2006
                                      • 0 Attachment
                                        > What if #if/#endif blocks are nested ?

                                        Yakov is correct, that nested #if/#endif blocks would cause
                                        trouble.

                                        My first thought at a [100% untested] solution would be
                                        something like

                                        :g/^\s*#endif/norm dV%

                                        which would find all of the #endif tokens and delete their
                                        associated blocks, exploiting Vim's ability to use "%" to
                                        match #if/#else/#endif blocks. However, funky behaviors
                                        emerge if you have an #else block, and you want some of it
                                        in to remain behind:

                                        #if COWS_ROLLERSKATE
                                        foo = "limbo, limbo";
                                        #else
                                        foo = "mu"
                                        #endif


                                        With my suggestion, you would delete the whole thing, and it
                                        would look like "foo" never gets set. It also nukes *all*
                                        the if/endif blocks, not just select ones (such as if you
                                        only wanted to nuke the "#if COWS_ROLLERSKATE" blocks, but
                                        not "#if POPE_CATHOLIC" blocks)

                                        If you don't have #else clauses, you might be able to solve
                                        that 2nd problem with something like

                                        :g/^\s*#if COWS_ROLLERSKATE/norm dV%

                                        Otherwise, you'd have to do some funky testing, along the
                                        lines of (again, 100% untested)

                                        :g/^\s*#if COWS/exec("norm %")| exec('norm
                                        '.(getline(".")=~'^\s*#else'?'%':'').'dV%')

                                        which should check if, after using "%", you landed on an
                                        #else line, in which case it adds an extra "%" to go to the
                                        "#endif" line before deleteing back to the original. All
                                        sorts of odd cases occur with nesting and #else blocks, so
                                        you'd have to tinker to get the desired behavior.

                                        -tim
                                      • Suresh Govindachar
                                        ... [In the above pseudo :%s expression, replace ifdef by just if.] I can think of three approaches, the second and third of which I have tested successfully.
                                        Message 19 of 26 , May 1, 2006
                                        • 0 Attachment
                                          On May 01, 2006, Yakov Lerner pointed out:

                                          >On 5/2/06, Suresh Govindachar wrote:
                                          >>
                                          >> Yakov Lerner wondered:
                                          >>
                                          >>> But how do you remove #ifdef blocks? I mentioned piping
                                          >>> because there is ready utility, 'unifdef', that removes some
                                          >>> or all of #if blocks.
                                          >>
                                          >> Isn't there a way to do a multi-line substitution:
                                          >>
                                          >> :%s/^\s*#ifdef .*^\s*#endif//
                                          >>
                                          >> where the *s are multi-line and non-greedy, or maybe I should
                                          >> say the *s are non-greedy and the . is multi-line? (I
                                          >> haven't actually tried, but I am confident I can do it in
                                          >> perl.)
                                          >
                                          > What if #if/#endif blocks are nested ?

                                          [In the above pseudo :%s expression, replace ifdef by just if.]
                                          I can think of three approaches, the second and third of which I
                                          have tested successfully. While the third is elegant for deleting
                                          #if/#endif blocks, the second is much more flexible.

                                          1) Have . not match ^\s*#if -- so that we can get rid of
                                          inner-most #if/#endif blocks. Repeat this in a while loop till
                                          there are no more ^\s*#if in the buffer.

                                          2) I successfully tested the following all-in-one-line command:

                                          :perl my $skip=0; my @extract=(); foreach my $line ($curbuf->Get(1 .. VIM::Eval('line("$")'))) { $line =~ /^\s*#if/ and
                                          $skip++; $skip or push @extract, $line; $line =~ /^\s*#endif/ and $skip--;} VIM::DoCommand('new'); $curbuf->Append(1, @extract);
                                          VIM::DoCommand('1d');

                                          with a file that looked like (note the nested, unaligned #if):

                                          stay
                                          stay, next blank too

                                          #if

                                          go away, previous blank too

                                          go away, previous blank too
                                          go away
                                          #if
                                          go away

                                          go away, previous blank too
                                          #endif

                                          some more go away
                                          #endif

                                          stay, previous blank too
                                          stay

                                          stay, previous blank too
                                          stay
                                          very last stay

                                          3) The following works on the above example

                                          :%/^\s*#if/normal d%dd

                                          Of course, the perl solution can be translated to other
                                          languages, including viml.

                                          --Suresh
                                        • Suresh Govindachar
                                          [In reporting the third solution below, I forgot the g] ... [In the above pseudo :%s expression, replace ifdef by just if.] I can think of three approaches,
                                          Message 20 of 26 , May 1, 2006
                                          • 0 Attachment
                                            [In reporting the third solution below, I forgot the g]

                                            On May 01, 2006, Yakov Lerner pointed out:

                                            >On 5/2/06, Suresh Govindachar wrote:
                                            >>
                                            >> Yakov Lerner wondered:
                                            >>
                                            >>> But how do you remove #ifdef blocks? I mentioned piping
                                            >>> because there is ready utility, 'unifdef', that removes some
                                            >>> or all of #if blocks.
                                            >>
                                            >> Isn't there a way to do a multi-line substitution:
                                            >>
                                            >> :%s/^\s*#ifdef .*^\s*#endif//
                                            >>
                                            >> where the *s are multi-line and non-greedy, or maybe I should
                                            >> say the *s are non-greedy and the . is multi-line? (I
                                            >> haven't actually tried, but I am confident I can do it in
                                            >> perl.)
                                            >
                                            > What if #if/#endif blocks are nested ?

                                            [In the above pseudo :%s expression, replace ifdef by just if.]
                                            I can think of three approaches, the second and third of which I
                                            have tested successfully. While the third is elegant for deleting
                                            #if/#endif blocks, the second is much more flexible.

                                            1) Have . not match ^\s*#if -- so that we can get rid of
                                            inner-most #if/#endif blocks. Repeat this in a while loop till
                                            there are no more ^\s*#if in the buffer.

                                            2) I successfully tested the following all-in-one-line command:

                                            :perl my $skip=0; my @extract=(); foreach my $line ($curbuf->Get(1 .. VIM::Eval('line("$")'))) { $line =~ /^\s*#if/ and
                                            $skip++; $skip or push @extract, $line; $line =~ /^\s*#endif/ and $skip--;} VIM::DoCommand('new'); $curbuf->Append(1, @extract);
                                            VIM::DoCommand('1d');

                                            with a file that looked like (note the nested, unaligned #if):

                                            stay
                                            stay, next blank too

                                            #if

                                            go away, previous blank too

                                            go away, previous blank too
                                            go away
                                            #if
                                            go away

                                            go away, previous blank too
                                            #endif

                                            some more go away
                                            #endif

                                            stay, previous blank too
                                            stay

                                            stay, previous blank too
                                            stay
                                            very last stay

                                            3) The following works on the above example

                                            :%/^\s*#if/normal d%dd

                                            Of course, the perl solution can be translated to other
                                            languages, including viml.

                                            --Suresh
                                          • Suresh Govindachar
                                            [Modified the third solution] ... [In the above pseudo :%s expression, replace ifdef by just if.] I can think of three approaches, the second and third of
                                            Message 21 of 26 , May 1, 2006
                                            • 0 Attachment
                                              [Modified the third solution]

                                              On May 01, 2006, Yakov Lerner pointed out:

                                              >On 5/2/06, Suresh Govindachar wrote:
                                              >>
                                              >> Yakov Lerner wondered:
                                              >>
                                              >>> But how do you remove #ifdef blocks? I mentioned piping
                                              >>> because there is ready utility, 'unifdef', that removes some
                                              >>> or all of #if blocks.
                                              >>
                                              >> Isn't there a way to do a multi-line substitution:
                                              >>
                                              >> :%s/^\s*#ifdef .*^\s*#endif//
                                              >>
                                              >> where the *s are multi-line and non-greedy, or maybe I should
                                              >> say the *s are non-greedy and the . is multi-line? (I
                                              >> haven't actually tried, but I am confident I can do it in
                                              >> perl.)
                                              >
                                              > What if #if/#endif blocks are nested ?

                                              [In the above pseudo :%s expression, replace ifdef by just if.]
                                              I can think of three approaches, the second and third of which I
                                              have tested successfully. While the third is elegant for deleting
                                              #if/#endif blocks, the second is much more flexible.

                                              1) Have . not match ^\s*#if -- so that we can get rid of
                                              inner-most #if/#endif blocks. Repeat this in a while
                                              loop till there are no more ^\s*#if in the buffer.

                                              2) I successfully tested the following all-in-one-line command
                                              (although it is written in multiple lines to make it easy
                                              to read):

                                              :perl my $skip=0; my @extract=();
                                              foreach my $line ($curbuf->Get(1 .. VIM::Eval('line("$")')))
                                              {
                                              $line =~ /^\s*#if/ and $skip++;
                                              $skip or push @extract, $line;
                                              $line =~ /^\s*#endif/ and $skip--;
                                              }
                                              VIM::DoCommand('new');
                                              $curbuf->Append(1, @extract);
                                              VIM::DoCommand('1d');

                                              with a file that looked like (note the nested, unaligned #if):

                                              stay
                                              stay, next blank too

                                              #if

                                              go away, previous blank too

                                              go away, previous blank too
                                              go away
                                              #if
                                              go away

                                              go away, previous blank too
                                              #endif

                                              some more go away
                                              #endif

                                              stay, previous blank too
                                              stay

                                              stay, previous blank too
                                              stay
                                              very last stay

                                              3) The following works on the above example

                                              :%g/^\s*#if/normal d%dd

                                              After seeing Tim Chase's post, noticed that the
                                              preceding doesn't handle elses; I think the
                                              following would do the job (only partially tested):

                                              :exec 'normal G$' | while(search('^\s*#endif\s*', 'bce')) | exec 'normal d%dd' | endwhile

                                              (Of course, the perl solution can be translated to other
                                              languages, including viml.)

                                              --Suresh
                                            • Jack Donohue
                                              ... Yes, I use this a lot if I just want to filter out a set of lines, or see only lines containing some text (like the old XEDIT command). But what I d
                                              Message 22 of 26 , May 4, 2006
                                              • 0 Attachment
                                                > :v (and :g) made my day..!

                                                Yes, I use this a lot if I just want to filter out a set of lines, or see
                                                only lines containing some text (like the old XEDIT command). But what I'd
                                                really like to to is continue editing in this view and not lose all the
                                                hidden lines, more like folding. I expect folding can do this, but I've
                                                never gotten it to work and it seems pretty cumbersome. I'm looking for a
                                                simple solution involving maybe a couple of command I can make a map for.

                                                I guess I'm looking for a g or v command that folds the lines instead of
                                                actually deleting them.

                                                Thanks,


                                                Jack
                                              • Gary Johnson
                                                ... The basic technique of using folding for this is this: set foldmethod=expr set foldexpr=getline(v:lnum)=~ text to be folded To close all the folds, you
                                                Message 23 of 26 , May 4, 2006
                                                • 0 Attachment
                                                  On 2006-05-04, Jack Donohue <jmdonohue@...> wrote:
                                                  > > :v (and :g) made my day..!
                                                  >
                                                  > Yes, I use this a lot if I just want to filter out a set of lines, or see
                                                  > only lines containing some text (like the old XEDIT command). But what I'd
                                                  > really like to to is continue editing in this view and not lose all the
                                                  > hidden lines, more like folding. I expect folding can do this, but I've
                                                  > never gotten it to work and it seems pretty cumbersome. I'm looking for a
                                                  > simple solution involving maybe a couple of command I can make a map for.
                                                  >
                                                  > I guess I'm looking for a g or v command that folds the lines instead of
                                                  > actually deleting them.

                                                  The basic technique of using folding for this is this:

                                                  set foldmethod=expr
                                                  set foldexpr=getline(v:lnum)=~'text to be folded'

                                                  To close all the folds, you can

                                                  set foldlevel=0

                                                  but I usually use zM to close all folds and zR to open all folds.

                                                  You could wrap that in a mapping and maybe a function to make it
                                                  easier to use. I usually type it out once, then use the command
                                                  line history and editing features to modify the pattern as needed.

                                                  See

                                                  :help fold-expr

                                                  HTH,
                                                  Gary

                                                  --
                                                  Gary Johnson | Agilent Technologies
                                                  garyjohn@... | Wireless Division
                                                  | Spokane, Washington, USA
                                                • Suresh Govindachar
                                                  ... The original post specifically asked for a non-fold based solution to hiding lines . The first step toward finding a non- cumbersome solution that can be
                                                  Message 24 of 26 , May 4, 2006
                                                  • 0 Attachment
                                                    Jack Donohue wrote:

                                                    >> :v (and :g) made my day..!
                                                    >
                                                    > Yes, I use this a lot if I just want to filter out a set of
                                                    > lines, or see only lines containing some text (like the old
                                                    > XEDIT command). But what I'd really like to to is continue
                                                    > editing in this view and not lose all the hidden lines, more
                                                    > like folding. I expect folding can do this, but I've never
                                                    > gotten it to work and it seems pretty cumbersome. I'm looking
                                                    > for a simple solution involving maybe a couple of command I can
                                                    > make a map for.
                                                    >
                                                    > I guess I'm looking for a g or v command that folds the lines
                                                    > instead of actually deleting them.

                                                    The original post specifically asked for a non-fold based solution
                                                    to "hiding lines".

                                                    The first step toward finding a non-"cumbersome" solution that can
                                                    be mapped and which results in folding away certain lines is to
                                                    define what needs to be hidden (with everything else displayed or
                                                    what needs to be displayed with everything else hidden).

                                                    --Suresh
                                                  • Gerald Lai
                                                    ... To fold consecutive lines that start with the word fold , first search /^fold or ... Then do ... to fold every search match. HTH. -- Gerald
                                                    Message 25 of 26 , May 4, 2006
                                                    • 0 Attachment
                                                      On Thu, 4 May 2006, Jack Donohue wrote:

                                                      >> :v (and :g) made my day..!
                                                      >
                                                      > Yes, I use this a lot if I just want to filter out a set of lines, or see
                                                      > only lines containing some text (like the old XEDIT command). But what I'd
                                                      > really like to to is continue editing in this view and not lose all the
                                                      > hidden lines, more like folding. I expect folding can do this, but I've
                                                      > never gotten it to work and it seems pretty cumbersome. I'm looking for a
                                                      > simple solution involving maybe a couple of command I can make a map for.
                                                      >
                                                      > I guess I'm looking for a g or v command that folds the lines instead of
                                                      > actually deleting them.

                                                      Perhaps this would do:

                                                      :set foldenable foldexpr=getline(v:lnum)=~@/

                                                      To fold consecutive lines that start with the word "fold", first search

                                                      /^fold

                                                      or

                                                      :let @/ = "^fold"

                                                      Then do

                                                      :set foldmethod=expr foldlevel=0

                                                      to fold every search match.

                                                      HTH.
                                                      --
                                                      Gerald
                                                    • Charles E Campbell Jr
                                                      ... May I suggest looking into Vince Negri s conceal patch, available at http://vim.sourceforge.net/scripts/script.php?script_id=302 It will not conceal the
                                                      Message 26 of 26 , May 5, 2006
                                                      • 0 Attachment
                                                        Suresh Govindachar wrote:

                                                        >Jack Donohue wrote:
                                                        >
                                                        > >> :v (and :g) made my day..!
                                                        > >
                                                        > > I guess I'm looking for a g or v command that folds the lines
                                                        > > instead of actually deleting them.
                                                        >
                                                        > The original post specifically asked for a non-fold based solution
                                                        > to "hiding lines".
                                                        >
                                                        >
                                                        May I suggest looking into Vince Negri's conceal patch, available at

                                                        http://vim.sourceforge.net/scripts/script.php?script_id=302

                                                        It will not conceal the current line, so one can always see and edit the
                                                        current line. Currently its
                                                        a vim 6.0 patch; I don't think VN has made one to vim 7.0 available
                                                        yet. It wasn't rated highly
                                                        enough for Bram to consider including it in vim 7.0, apparently.

                                                        Regards,
                                                        Chip Campbell
                                                      Your message has been successfully submitted and would be delivered to recipients shortly.