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

Vim search highlight bug (I think)

Expand Messages
  • Halim, Salman
    I ve noticed an inconsistency (to me) in the highlights of search strings (Vim 7); take the following snippet: set hlsearch DO THIS: Search for something
    Message 1 of 4 , Feb 2, 2006
    • 0 Attachment
      I've noticed an inconsistency (to me) in the highlights of search
      strings (Vim 7); take the following snippet:

      set hlsearch
      " DO THIS: Search for something simply like "ea" (without the quotes)
      nohls function! TestN()
      execute 'normal! n'
      endfunction
      nmap n1 :execute 'normal! n'<cr>
      nmap n2 :call TestN()<cr>

      Note how hitting n1 restores the highlight but hitting n2 does not, even
      though it does locate the search term.

      Also, if I'm currently searching for something and I do something like
      this:

      execute "normal /somethingElse\<CR>"

      If I type this by hand, everything works as you'd expect. However,
      inside a function, the search works, but not only does it not change the
      search highlighting from the previous string, hitting n keeps going to
      the old search string.

      Am I missing something or have I uncovered something sinister here?

      Thanks!

      Salman.
    • Bram Moolenaar
      ... When you call a function the search pattern is saved and restored. I can t find the place in the help files where this is mentioned... -- The amigos also
      Message 2 of 4 , Feb 2, 2006
      • 0 Attachment
        > I've noticed an inconsistency (to me) in the highlights of search
        > strings (Vim 7); take the following snippet:
        >
        > set hlsearch
        > " DO THIS: Search for something simply like "ea" (without the quotes)
        > nohls function! TestN()
        > execute 'normal! n'
        > endfunction
        > nmap n1 :execute 'normal! n'<cr>
        > nmap n2 :call TestN()<cr>
        >
        > Note how hitting n1 restores the highlight but hitting n2 does not, even
        > though it does locate the search term.
        >
        > Also, if I'm currently searching for something and I do something like
        > this:
        >
        > execute "normal /somethingElse\<CR>"
        >
        > If I type this by hand, everything works as you'd expect. However,
        > inside a function, the search works, but not only does it not change the
        > search highlighting from the previous string, hitting n keeps going to
        > the old search string.
        >
        > Am I missing something or have I uncovered something sinister here?

        When you call a function the search pattern is saved and restored.

        I can't find the place in the help files where this is mentioned...

        --
        "The amigos also appear to be guilty of not citing the work of others who had
        gone before them. Even worse, they have a chapter about modeling time and
        space without making a single reference to Star Trek!"
        (Scott Ambler, reviewing the UML User Guide)

        /// Bram Moolenaar -- Bram@... -- http://www.Moolenaar.net \\\
        /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
        \\\ download, build and distribute -- http://www.A-A-P.org ///
        \\\ help me help AIDS victims -- http://www.ICCF.nl ///
      • Halim, Salman
        Okay, I can work around that by having the function return the string to ... But what about the first example, where I m simply doing the equivalent of hitting
        Message 3 of 4 , Feb 2, 2006
        • 0 Attachment
          Okay, I can work around that by having the function return the string to
          be searched and doing something like:

          :let @/=MyFunctionCall()

          But what about the first example, where I'm simply doing the equivalent
          of hitting 'n'? That doesn't change the search pattern...

          Thanks,

          Salman.

          > -----Original Message-----
          > From: Bram@... [mailto:Bram@...]
          > Sent: Thursday, February 02, 2006 11:16 AM
          > To: Halim, Salman
          > Cc: vim-dev@...
          > Subject: Re: Vim search highlight bug (I think)
          >
          >
          > > I've noticed an inconsistency (to me) in the highlights of search
          > > strings (Vim 7); take the following snippet:
          > >
          > > set hlsearch
          > > " DO THIS: Search for something simply like "ea" (without
          > the quotes)
          > > nohls function! TestN()
          > > execute 'normal! n'
          > > endfunction
          > > nmap n1 :execute 'normal! n'<cr>
          > > nmap n2 :call TestN()<cr>
          > >
          > > Note how hitting n1 restores the highlight but hitting n2 does not,
          > > even though it does locate the search term.
          > >
          > > Also, if I'm currently searching for something and I do
          > something like
          > > this:
          > >
          > > execute "normal /somethingElse\<CR>"
          > >
          > > If I type this by hand, everything works as you'd expect. However,
          > > inside a function, the search works, but not only does it
          > not change
          > > the search highlighting from the previous string, hitting n keeps
          > > going to the old search string.
          > >
          > > Am I missing something or have I uncovered something sinister here?
          >
          > When you call a function the search pattern is saved and restored.
          >
          > I can't find the place in the help files where this is mentioned...
          >
          > --
          > "The amigos also appear to be guilty of not citing the work
          > of others who had gone before them. Even worse, they have a
          > chapter about modeling time and space without making a single
          > reference to Star Trek!"
          > (Scott Ambler, reviewing the UML User Guide)
          >
          > /// Bram Moolenaar -- Bram@... --
          > http://www.Moolenaar.net \\\
          > /// sponsor Vim, vote for features --
          > http://www.Vim.org/sponsor/ \\\
          > \\\ download, build and distribute --
          > http://www.A-A-P.org ///
          > \\\ help me help AIDS victims --
          > http://www.ICCF.nl ///
          >
        • Benji Fisher
          ... It is at the end of the long paragraph under ... just above ... In other words, ... restores the search highlighting, but ... n1 (where n1 is mapped as
          Message 4 of 4 , Feb 3, 2006
          • 0 Attachment
            On Thu, Feb 02, 2006 at 11:19:34AM -0500, Halim, Salman wrote:
            >
            > > -----Original Message-----
            > > From: Bram@... [mailto:Bram@...]
            > > Sent: Thursday, February 02, 2006 11:16 AM
            > >
            > > > I've noticed an inconsistency (to me) in the highlights of search
            > > > strings (Vim 7); take the following snippet:
            > > >
            > > > set hlsearch
            > > > " DO THIS: Search for something simply like "ea" (without
            > > > the quotes)
            > > > nohls function! TestN()
            > > > execute 'normal! n'
            > > > endfunction
            > > > nmap n1 :execute 'normal! n'<cr>
            > > > nmap n2 :call TestN()<cr>
            > > >
            > > > Note how hitting n1 restores the highlight but hitting n2 does not,
            > > > even though it does locate the search term.
            > > >
            > > > Am I missing something or have I uncovered something sinister here?
            > >
            > > When you call a function the search pattern is saved and restored.
            > >
            > > I can't find the place in the help files where this is mentioned...

            It is at the end of the long paragraph under

            :help :function

            just above

            :help :endfunction

            > But what about the first example, where I'm simply doing the equivalent
            > of hitting 'n'? That doesn't change the search pattern...

            In other words,

            :noh
            :execute 'normal! n'

            restores the search highlighting, but

            :noh
            n1

            (where "n1" is mapped as above) does not. This does seem like a bug to
            me. (I just tested it under vim 6.4, but you say it behaves the same
            under vim 7.) After all, :nmap is supposed to behave the same as if you
            typed the keys yourself.

            HTH --Benji Fisher
          Your message has been successfully submitted and would be delivered to recipients shortly.