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

hiding lines

Expand Messages
  • 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 1 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?
    • 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 2 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 3 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 4 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 5 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 6 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 7 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 8 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 9 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 10 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 11 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 12 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 13 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 14 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 15 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 16 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.