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

How to separate consecutive highlighted matches?

Expand Messages
  • Peng Yu
    Hi I have the following code in ~/.vimrc, by which I can toggle on or off highlight of matches. function ToggleHLSearch() if &hls set nohls else set hls endif
    Message 1 of 2 , Oct 1, 2009
    • 0 Attachment
      Hi

      I have the following code in ~/.vimrc, by which I can toggle on or off
      highlight of matches.

      function ToggleHLSearch()
      if &hls
      set nohls
      else
      set hls
      endif
      endfunction
      nmap <silent> <C-n> :silent call ToggleHLSearch()<CR>

      But if I have consecutive matches, it is still not easy to see how
      many matches there are. In particular, '\t' can occupy different
      length of spaces, depending the context. Therefore, I would like the
      highlight be nonconsecutive (for example, one pixel with between two
      matches is not highlighted).

      I'm wondering if there is such an option in vim. Thank you!

      Regards,
      Peng
      --~--~---------~--~----~------------~-------~--~----~
      You received this message from the "vim_use" maillist.
      For more information, visit http://www.vim.org/maillist.php
      -~----------~----~----~----~------~----~------~--~---
    • Tim Chase
      ... As an aside, this can be simplified using the inv erse notation for any boolean setting, written as either ... or ... I use this regularly with list to
      Message 2 of 2 , Oct 1, 2009
      • 0 Attachment
        > function ToggleHLSearch()
        > if &hls
        > set nohls
        > else
        > set hls
        > endif
        > endfunction
        > nmap <silent> <C-n> :silent call ToggleHLSearch()<CR>

        As an aside, this can be simplified using the "inv"erse notation
        for any boolean setting, written as either

        :set invhls

        or

        :set hls!

        I use this regularly with 'list' to toggle between set/unset with
        ":set list!" which is documented in the help at the bottom of the

        :help E518

        section.


        > But if I have consecutive matches, it is still not easy to see how
        > many matches there are. In particular, '\t' can occupy different
        > length of spaces, depending the context. Therefore, I would like the
        > highlight be nonconsecutive (for example, one pixel with between two
        > matches is not highlighted).

        To the best of my knowledge, I don't believe you can do this,
        especially in non-GUI vim -- character-cells don't have spacing,
        and if they did, you'd get gaps between *all* the cells in the
        highlighted range. The best I could come up with was to use the
        \zs or \ze token in the regexp to tell vim when to start/stop
        highlighting to omit the delimiting space/tab character from
        being highlighted.

        -tim





        --~--~---------~--~----~------------~-------~--~----~
        You received this message from the "vim_use" maillist.
        For more information, visit http://www.vim.org/maillist.php
        -~----------~----~----~----~------~----~------~--~---
      Your message has been successfully submitted and would be delivered to recipients shortly.