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

Re: Highlighting :g//

Expand Messages
  • Jürgen Krämer
    Hi, ... this is almost completely untested (especially for corner cases): function! PrintWithHighlighting() let line = getline( . ) let ms = match(line, @/)
    Message 1 of 6 , Apr 2, 2012
      Hi,

      Paul wrote:
      >
      > Often I'll want to see a list of lines that contain a pattern. I'll do
      > ':g/pattern/', sometimes followed by # if I want the line numbers.
      > Sometimes I'd like to see where in the line the pattern matched, so,
      > is there a way to have the output of :g// highlight the pattern?

      this is almost completely untested (especially for corner cases):

      function! PrintWithHighlighting()
      let line = getline('.')
      let ms = match(line, @/)
      let me = matchend(line, @/)

      if ms != -1
      echohl none
      echo strpart(line, 0, ms)
      echohl Search
      echon strpart(line, ms, me - ms)
      echohl none
      echon strpart(line, me, strlen(line))
      else
      echo line
      endif
      endfunction

      command! P call PrintWithHighlighting()

      Use it like

      :g/your pattern/P

      Regards,
      Jürgen

      --
      Sometimes I think the surest sign that intelligent life exists elsewhere
      in the universe is that none of it has tried to contact us. (Calvin)

      --
      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
      ... Try Yakov Lerner s PP.vim script, ... Works great. Regards, Gary -- You received this message from the vim_use maillist. Do not top-post! Type your reply
      Message 2 of 6 , Apr 2, 2012
        On 2012-04-02, Paul wrote:
        > Often I'll want to see a list of lines that contain a pattern.
        > I'll do ':g/pattern/', sometimes followed by # if I want the line
        > numbers. Sometimes I'd like to see where in the line the pattern
        > matched, so, is there a way to have the output of :g// highlight
        > the pattern?

        Try Yakov Lerner's PP.vim script,
        http://vim.wikia.com/wiki/VimTip1141. Use it like this:

        :g/pattern/PP

        Works great.

        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
      • Thilo Six
        Hello Paul, ... I recently did the same. What i used was vimgrep, e.g.: vimgrep /pat1 |pat2/ % | botright copen: The copen part opens up the so called quickfix
        Message 3 of 6 , Apr 2, 2012
          Hello Paul,


          Excerpt from Paul:
          > Often I'll want to see a list of lines that contain a pattern. I'll do
          > ':g/pattern/', sometimes followed by # if I want the line numbers. Sometimes
          > I'd like to see where in the line the pattern matched, so, is there a way to
          > have the output of :g// highlight the pattern?

          I recently did the same. What i used was vimgrep, e.g.:
          vimgrep /pat1\|pat2/ % | botright copen:

          The copen part opens up the so called quickfix window. With that you can
          breezingly jump from hit to an other AND get a nice overview of each line that
          has a match at the same time.
          Add a mapping for ':cnext' ':cprev' (aka next and previos match) and you can
          move through the list.

          --
          Regards,
          Thilo

          4096R/0xC70B1A8F
          721B 1BA0 095C 1ABA 3FC6 7C18 89A4 A2A0 C70B 1A8F


          --
          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
        • Thilo Six
          Hello ... ^- copy and paste error, no colon there ... -- Regards, Thilo 4096R/0xC70B1A8F 721B 1BA0 095C 1ABA 3FC6 7C18 89A4 A2A0 C70B 1A8F -- You received
          Message 4 of 6 , Apr 2, 2012
            Hello


            Excerpt from Thilo Six:

            > Hello Paul,
            >
            >
            > Excerpt from Paul:
            >> Often I'll want to see a list of lines that contain a pattern. I'll do
            >> ':g/pattern/', sometimes followed by # if I want the line numbers. Sometimes
            >> I'd like to see where in the line the pattern matched, so, is there a way to
            >> have the output of :g// highlight the pattern?
            >
            > I recently did the same. What i used was vimgrep, e.g.:
            > vimgrep /pat1\|pat2/ % | botright copen:
            ^- copy and paste error, no colon there
            >
            > The copen part opens up the so called quickfix window. With that you can
            > breezingly jump from hit to an other AND get a nice overview of each line that
            > has a match at the same time.
            > Add a mapping for ':cnext' ':cprev' (aka next and previos match) and you can
            > move through the list.
            >

            --
            Regards,
            Thilo

            4096R/0xC70B1A8F
            721B 1BA0 095C 1ABA 3FC6 7C18 89A4 A2A0 C70B 1A8F


            --
            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
          • Paul
            ... Indeed it does, thanks. -- . -- You received this message from the vim_use maillist. Do not top-post! Type your reply below the text you are replying to.
            Message 5 of 6 , Apr 3, 2012
              On Monday, 02 April, 2012 at 16:54:22 BST, Gary Johnson wrote:
              >> Often I'll want to see a list of lines that contain a pattern.
              >> I'll do ':g/pattern/', sometimes followed by # if I want the line
              >> numbers. Sometimes I'd like to see where in the line the pattern
              >> matched, so, is there a way to have the output of :g// highlight
              >> the pattern?
              >
              >Try Yakov Lerner's PP.vim script,
              >http://vim.wikia.com/wiki/VimTip1141. Use it like this:
              >
              > :g/pattern/PP
              >
              >Works great.

              Indeed it does, thanks.

              --

              .

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