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

Change highlighted pattern, don't move cursor/window

Expand Messages
  • Fred Ma
    Hi, When I use vim to search for a pattern with the / , the cursor moves to the next occurance, and all matching text is highlighted. That s almost exactly
    Message 1 of 3 , Jan 31, 2004
      Hi,

      When I use vim to search for a pattern with the "/",
      the cursor moves to the next occurance, and all matching
      text is highlighted. That's almost exactly what I want.
      I want to provide a pattern to highlight from the command
      line, but I don't want the cursor to move, or the window
      to scroll. I thought I could find where vim stores it's
      notion of last pattern searched for, but can't seem to
      find it. It isn't in hlsearch or search(). Is this
      possible?

      Fred

      P.S. Posted to comp.editors and vim@....
      --
      Fred Ma
      Dept. of Electronics, Carleton University
      1125 Colonel By Drive, Ottawa, Ontario
      Canada, K1S 5B6
    • Gary Johnson
      ... How about this? ... See ... Vim keeps the search pattern in the / register, so you could also ... but that won t highlight the pattern unless search
      Message 2 of 3 , Feb 1, 2004
        On 2004-02-01, Fred Ma <fma@...> wrote:
        > Hi,
        >
        > When I use vim to search for a pattern with the "/",
        > the cursor moves to the next occurance, and all matching
        > text is highlighted. That's almost exactly what I want.
        > I want to provide a pattern to highlight from the command
        > line, but I don't want the cursor to move, or the window
        > to scroll. I thought I could find where vim stores it's
        > notion of last pattern searched for, but can't seem to
        > find it. It isn't in hlsearch or search(). Is this
        > possible?

        How about this?

        :match Search /pattern/

        See

        :help match

        Vim keeps the search pattern in the "/ register, so you could also
        do this:

        :let @/ = "pattern"

        but that won't highlight the pattern unless search highlighting is
        already turned on. To turn in on, you can

        :set hls

        See also

        :help quote/
        :help @/

        HTH,
        Gary

        --
        Gary Johnson | Agilent Technologies
        garyjohn@... | Wireless Division
        | Spokane, Washington, USA
      • Fred Ma
        ... That doesn t seem to do it. It only highlights the next occurance. Also, in order not to move the cursor, I have to not complete the search command,
        Message 3 of 3 , Feb 1, 2004
          Sven Guckes wrote:
          >
          > * Fred Ma <fma@...> [2004-02-01]:
          > > When I use vim to search for a pattern with the "/", the
          > > cursor moves to the next occurance, and all matching text is
          > > highlighted. That's almost exactly what I want. I want to
          > > provide a pattern to highlight from the command line, but I
          > > don't want the cursor to move, or the window to scroll.
          >
          > sounds like you want "incremental search". see ":help incsearch".

          That doesn't seem to do it. It only highlights the next
          occurance. Also, in order not to move the cursor, I have
          to not complete the search command, which terminates even
          that highlighting.

          > > I thought I could find where vim stores it's notion of last
          > > pattern searched for, but can't seem to find it.
          >
          > the last search pattern is in register '/'.

          I tried yanking a search expression into register '/', but
          turns out that it's not possible (the help on registers).
          Fortunately, I can assign to register "/", and it does
          force highlighting of all text matching the new expression.

          Thanks for the hint on which register to read up on.

          Fred
          --
          Fred Ma
          Dept. of Electronics, Carleton University
          1125 Colonel By Drive, Ottawa, Ontario
          Canada, K1S 5B6
        Your message has been successfully submitted and would be delivered to recipients shortly.