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

Re: Inverse Folding?

Expand Messages
  • Charles E Campbell Jr
    ... I have the following in my : nnoremap :exe silent! normal! .((foldclosed( . ) 0)? zMzx : zc ) This map is useful
    Message 1 of 8 , Dec 1, 2006
    • 0 Attachment
      Vigil wrote:

      > Because I often want to concentrate on a small section of code in a
      > large script, and because my terminal window is large, I wondered if
      > it was possible to select some text and have all other text, ie. the
      > surrounding text, fade out in colour, or use a darker colour or
      > something, so that when I flick away to read another tab and flick
      > back, I don't have to manually search out the small block of code again.
      >
      > I did a search on vim.org to see if anyone had already done this, but
      > came across a tip that lead me to manually fold away the code that I
      > don't want to see, ie. the code above, and the code below, the subject
      > code.
      >
      > Now I'm wondering if it is possible to select a block of text and
      > issue a fold command that folds away everything BUT the selected text.
      >
      I have the following in my <.vimrc>:

      nnoremap <silent> <space> :exe 'silent! normal!
      '.((foldclosed('.')>0)? 'zMzx' : 'zc')<cr>

      This map is useful for when you have syntax or marker based folding
      enabled. Just go someplace, and while in normal mode use the <space> bar.

      Now, if your file isn't already supporting a bunch of folds, then you'll
      want to manually fold code above and below as you have been doing. To
      simplify the process:

      vnoremap <silent> <space> :fo<bar>1,'<-1fo<bar>'>+1,$fo<cr>

      With these two maps you have a solution! Just visually select the
      region of interest, then hit your space bar twice. Plus, each map by
      itself is useful.

      Regards,
      Chip Campbell
    • Tim Chase
      ... vnoremap h : exec match Comment / % ). l | % .line( ). l/ seems to do what you re describing (that | might have to be
      Message 2 of 8 , Dec 1, 2006
      • 0 Attachment
        > Because I often want to concentrate on a small section of code in a large
        > script, and because my terminal window is large, I wondered if it was possible
        > to select some text and have all other text, ie. the surrounding text, fade out
        > in colour, or use a darker colour or something, so that when I flick away to
        > read another tab and flick back, I don't have to manually search out the small
        > block of code again.

        vnoremap h :<c-u>exec 'match Comment
        /\%<'.line("'<lt>").'l\\|\%>'.line("'>").'l/'<cr>

        seems to do what you're describing (that "|" might have to be
        "<bar>" depending how vnoremap treats things in strings...).
        Adjust "Comment" to be whatever highlight group you like...or
        make your own and make it invisible. For me, Comment is
        [italic-]dark-grey-on-black which fades out. Then, with a block
        highlighted, you can hit "h" and it will "mask" all the stuff
        that wasn't highlighted.

        As usual, you can then just

        :match none

        to clear it.

        > Now I'm wondering if it is possible to select a block of text and issue a fold
        > command that folds away everything BUT the selected text.

        A similar stunt could be done to clear all folding, and then fold
        the two ranges "1,'>-" and "'>+,$" something like this untested

        vnoremap h :<c-u>1,'<lt>-fold<bar>'>+,$fold<cr>


        HTH,

        -tim
      • Vigil
        ... That, combined with foldmethod=manual, is perfect. Thanks, Tim and Charles. -- .
        Message 3 of 8 , Dec 3, 2006
        • 0 Attachment
          On Fri, 1 Dec 2006, Tim Chase wrote:

          > A similar stunt could be done to clear all folding, and then fold the two
          > ranges "1,'>-" and "'>+,$" something like this untested
          >
          > vnoremap h :<c-u>1,'<lt>-fold<bar>'>+,$fold<cr>

          That, combined with foldmethod=manual, is perfect. Thanks, Tim and Charles.

          --

          .
        • Vigil
          ... Sooo... vnoremap h set foldmethod=manual | : 1, -fold +,$fold doesn t work :) -- .
          Message 4 of 8 , Dec 3, 2006
          • 0 Attachment
            On Sun, 3 Dec 2006, Vigil wrote:

            >> vnoremap h :<c-u>1,'<lt>-fold<bar>'>+,$fold<cr>
            >
            > That, combined with foldmethod=manual, is perfect. Thanks, Tim and Charles.

            Sooo...

            vnoremap h set foldmethod=manual | :<c-u>1,'<lt>-fold<bar>'>+,$fold<cr>

            doesn't work :)

            --

            .
          • Tim Chase
            ... I think you want vnoremap h : set foldmethod=manual 1, -fold +,$fold (on one line in case mailers decide to bung it) You might also
            Message 5 of 8 , Dec 3, 2006
            • 0 Attachment
              >>> vnoremap h :<c-u>1,'<lt>-fold<bar>'>+,$fold<cr>
              >> That, combined with foldmethod=manual, is perfect. Thanks, Tim and Charles.
              >
              > Sooo...
              >
              > vnoremap h set foldmethod=manual | :<c-u>1,'<lt>-fold<bar>'>+,$fold<cr>
              >
              > doesn't work :)

              I think you want

              vnoremap h :<c-u>set foldmethod=manual<bar>
              1,'<lt>-fold<bar>'>+,$fold<cr>

              (on one line in case mailers decide to bung it)

              You might also want to add in

              exec "norm zE"

              in there after the "foldmethod=manual" to clear out any existing
              folds, as switching foldmethod to manual (having been something
              else previously) will keep those folds. Funky things happen when
              folds overlap (as in "well-formed XML") so Vim tries to do the
              smart thing with them, but it may not be what you expect...thus
              you may want to use "zE" to clear out previously existing folds.

              -tim
            • Vigil
              ... What is the for? I don t see any :help for it and ctrl-u just goes up a page normally, and clears the line to the left of the cursor in command mode.
              Message 6 of 8 , Dec 3, 2006
              • 0 Attachment
                On Sun, 3 Dec 2006, Tim Chase wrote:

                > vnoremap h :<c-u>set foldmethod=manual<bar> 1,'<lt>-fold<bar>'>+,$fold<cr>

                What is the <c-u> for? I don't see any :help for it and ctrl-u just goes up a
                page normally, and clears the line to the left of the cursor in command mode.

                --

                .
              • Tim Chase
                ... When in visual mode, when you press the colon, Vim prepopulates the command-line with
                Message 7 of 8 , Dec 3, 2006
                • 0 Attachment
                  >> vnoremap h :<c-u>set foldmethod=manual<bar> 1,'<lt>-fold<bar>'>+,$fold<cr>
                  >
                  > What is the <c-u> for? I don't see any :help for it and ctrl-u just goes up a
                  > page normally

                  When in visual mode, when you press the colon, Vim prepopulates
                  the command-line with "'<,'>". The ^U clears the line of that text.

                  :help c_CTRL-u

                  Otherwise, the resulting line would be

                  :'<,'>set foldmethod=manual<bar>...

                  and you'd get an error that "set" doesn't take a range.

                  -tim
                • Vigil
                  ... Aha, thanks. -- .
                  Message 8 of 8 , Dec 3, 2006
                  • 0 Attachment
                    > When in visual mode, when you press the colon, Vim prepopulates the
                    > command-line with "'<,'>". The ^U clears the line of that text.

                    Aha, thanks.

                    --

                    .
                  Your message has been successfully submitted and would be delivered to recipients shortly.