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

Re: Highlighting block of text

Expand Messages
  • richard emberson
    Andy, Have you tried your suggestion? If it works, could you share your code? Richard ... -- Quis custodiet ipsos custodes -- You received this message from
    Message 1 of 10 , May 8, 2012
    View Source
    • 0 Attachment
      Andy,

      Have you tried your suggestion? If it works, could you
      share your code?

      Richard

      On 05/08/2012 03:10 PM, Andrew Long wrote:
      >
      > On 8 May 2012, at 23:08, Richard wrote:
      >
      >> Well, I spoke too soon. What I wanted was to highlight
      >> multiple block with different colors *at the same time*
      >> Seems that match only works on a single pattern at a time.
      >>
      >> Richard
      >
      > You could try generating a random name for each block? or base it off the line/column pairs?
      >
      > Regards, Andy
      >
      >
      >>
      >> On May 8, 3:01 pm, richard emberson<richard.ember...@...>
      >> wrote:
      >>> Tim,
      >>>
      >>> I finally got to the point in my project where I could tryout
      >>> your code. In one sense your code was similar to some of
      >>> my attempts at using the match/highlight capability but
      >>> I 1) did not order the column/line correctly and, more
      >>> importantly, 2) I did not have a trailing '.' in the
      >>> match patterns.
      >>>
      >>> If one is willing to create highlight groups on the fly,
      >>> then one can programatically highlight arbitrary
      >>> blocks of code ... W5!
      >>>
      >>> function! XXX(name, c1, c2, l1, l2)
      >>> exec "highlight! " . a:name . " ctermbg=green guibg=green"
      >>> exec "sil! match " . a:name. ' /\%>' .a:c1. 'c\%<' .a:c2. 'c\%>'
      >>> .a:l1. 'l\%<' .a:l2. 'l./'
      >>> endfunction
      >>>
      >>> map<Leader>h :call XXX("Foo33",8,21,5,14)<CR>
      >>>
      >>> Thanks.
      >>>
      >>> Richard Emberson
      >>>
      >>> ps: 5W == Which Was What We Wanted
      >>>
      >>> On 05/06/2012 05:12 PM, Tim Chase wrote:
      >>>
      >>>
      >>>
      >>>
      >>>
      >>>
      >>>
      >>>
      >>>
      >>>> On 05/06/12 16:14, Richard wrote:
      >>>>> I'd like to highlight an arbitrary block of text even when
      >>>>> normal syntax-base highlighting is in effect.
      >>>>> Now, one can highlight a block of height 1 using matching:
      >>>>> :hi Green ctermbg=Green
      >>>>> :match Green /\%10l\%30c.*\%40c\%10l/
      >>>>> :match none
      >>>>> But what I'd like to do is for a block with height
      >>>>> greater than 1; something like what can be done
      >>>>> with Cntl-V visual block selection but without using
      >>>>> visual selection.
      >>>>> I've search the net without finding a solution.
      >>>>> Is it possible?
      >>>
      >>>> I'm not sure if this does what you want, but I threw it together in
      >>>> the hopes that it was close. Just visually highlight the range
      >>>> (linewise, characterwise, or blockwise) that you want to highlight
      >>>> and press<f4>. Adjust the "Error" at the bottom for whatever
      >>>> highlighting group you want (in the case of your example, "Green")
      >>>
      >>>> -tim
      >>>
      >>>> function! Hi(scheme)
      >>>> let l:mode=visualmode()
      >>>> let [_, lnum1, col1, _]=getpos("'<")
      >>>> let [_, lnum2, col2, _]=getpos("'>")
      >>>> if l:mode == 'v'
      >>>> if lnum1==lnum2
      >>>> let range='\%'.lnum1.'l\%>'.(col1-1).'c.*\%<'.(col2+1).'c'
      >>>> else
      >>>> let range=join([
      >>>> \'\%'.lnum1.'l\%>'.(col1-1).'c.*',
      >>>> \'.*\%'.lnum2.'l\%<'.(col2+1).'c',
      >>>> \'\%>'.lnum1.'l\%<'.lnum2.'l',
      >>>> \], '\|')
      >>>> endif
      >>>> else
      >>>> let left=min([col1, col2])
      >>>> let right=max([col1, col2])
      >>>> let top=min([lnum1, lnum2])
      >>>> let bottom=max([lnum1, lnum2])
      >>>> if l:mode == 'V'
      >>>> let range=
      >>>> \'\%>'.(top-1).'l'.
      >>>> \'\%<'.(bottom+1).'l'.
      >>>> \'.'
      >>>> else " visual block
      >>>> let range=
      >>>> \'\%>'.(left-1).'c'.
      >>>> \'\%<'.(right+1).'c'.
      >>>> \'\%>'.(top-1).'l'.
      >>>> \'\%<'.(bottom+1).'l'.
      >>>> \'.'
      >>>> endif
      >>>> endif
      >>>> exec printf('sil! match %s /%s/', a:scheme, range)
      >>>> endfunction
      >>>> vnoremap<f4> :<c-u>call Hi("Error")<cr>
      >>>> nnoremap<f4> :match NONE<cr>
      >>>
      >>> --
      >>> Quis custodiet ipsos custodes
      >>
      >> --
      >> You received this message from the "vim_use" maillist.
      >> Do not top-post! Type your reply below the text you are replying to.
      >> For more information, visit http://www.vim.org/maillist.php
      >

      --
      Quis custodiet ipsos custodes

      --
      You received this message from the "vim_use" maillist.
      Do not top-post! Type your reply below the text you are replying to.
      For more information, visit http://www.vim.org/maillist.php
    • Gary Johnson
      ... Use matchadd() instead. Regards, Gary -- You received this message from the vim_use maillist. Do not top-post! Type your reply below the text you are
      Message 2 of 10 , May 8, 2012
      View Source
      • 0 Attachment
        On 2012-05-08, Richard wrote:
        > Well, I spoke too soon. What I wanted was to highlight
        > multiple block with different colors *at the same time*
        > Seems that match only works on a single pattern at a time.

        Use matchadd() instead.

        Regards,
        Gary

        --
        You received this message from the "vim_use" maillist.
        Do not top-post! Type your reply below the text you are replying to.
        For more information, visit http://www.vim.org/maillist.php
      • Tim Chase
        ... Hopefully made easier by the code I gave which builds up a regexp string that is then simply evaluated, which could instead just be passed to matchadd()
        Message 3 of 10 , May 8, 2012
        View Source
        • 0 Attachment
          On 05/08/12 17:45, Gary Johnson wrote:
          > On 2012-05-08, Richard wrote:
          >> Well, I spoke too soon. What I wanted was to highlight
          >> multiple block with different colors *at the same time*
          >> Seems that match only works on a single pattern at a time.
          >
          > Use matchadd() instead.

          Hopefully made easier by the code I gave which builds up a regexp
          string that is then simply evaluated, which could instead just be
          passed to matchadd() with some appropriate highlighting-group
          designation.

          -tim


          --
          You received this message from the "vim_use" maillist.
          Do not top-post! Type your reply below the text you are replying to.
          For more information, visit http://www.vim.org/maillist.php
        • richard emberson
          Success ... Tim, note that the leading and trailing / (patterns generated by your example code) should not be included. So, folks should modify your Hi
          Message 4 of 10 , May 8, 2012
          View Source
          • 0 Attachment
            Success

            :exec "highlight! Foo33 ctermbg=green guibg=green"
            :call matchadd("Foo33", '\%>8c\%<21c\%>5l\%<14l.')
            :call matchadd("Foo33", '\%>2c\%<11c\%>3l\%<6l.')

            :exec "highlight! Foo34 ctermbg=white guibg=white"
            :call matchadd("Foo34", '\%>18c\%<31c\%>5l\%<14l.')
            :call matchadd("Foo34", '\%>12c\%<21c\%>3l\%<6l.')


            :call clearmatches()

            Tim, note that the leading and trailing '/' (patterns
            generated by your example code) should not
            be included. So, folks should modify your "Hi" function
            to remove them if they wish to use matchadd().

            Thanks all.

            Richard


            On 05/08/2012 04:14 PM, Tim Chase wrote:
            > On 05/08/12 17:45, Gary Johnson wrote:
            >> On 2012-05-08, Richard wrote:
            >>> Well, I spoke too soon. What I wanted was to highlight
            >>> multiple block with different colors *at the same time*
            >>> Seems that match only works on a single pattern at a time.
            >>
            >> Use matchadd() instead.
            >
            > Hopefully made easier by the code I gave which builds up a regexp
            > string that is then simply evaluated, which could instead just be
            > passed to matchadd() with some appropriate highlighting-group
            > designation.
            >
            > -tim
            >
            >

            --
            Quis custodiet ipsos custodes

            --
            You received this message from the "vim_use" maillist.
            Do not top-post! Type your reply below the text you are replying to.
            For more information, visit http://www.vim.org/maillist.php
          • lessthanideal
            ... You ve solved your problem, but there s also this tip/plugin which seems to do something similar. http://vim.wikia.com/wiki/VimTip1572 It highlights
            Message 5 of 10 , May 9, 2012
            View Source
            • 0 Attachment
              On May 6, 10:14 pm, Richard <richard.ember...@...> wrote:
              > I'd like to highlight an arbitrary block of text even when
              > normal syntax-base highlighting is in effect.

              You've solved your problem, but there's also this
              tip/plugin which seems to do something similar.

              http://vim.wikia.com/wiki/VimTip1572

              It highlights arbitrary Visual and Visual Line selections, it
              doesn't pick up Visual Block selections but it can do
              blocks using this sort of command.

              :Highlight 1 \%>8c\%<21c\%>5l\%<14l.

              regards,
              Geoff

              --
              You received this message from the "vim_use" maillist.
              Do not top-post! Type your reply below the text you are replying to.
              For more information, visit http://www.vim.org/maillist.php
            Your message has been successfully submitted and would be delivered to recipients shortly.