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

How to use matcharg(2)[1] to set search register?

Expand Messages
  • Bee
    2match has been set and is working. ... Why does this not set the search register? let @/=matcharg(2)[1] matcharg({nr}) *matcharg()* Selects the
    Message 1 of 13 , Jun 24, 2012
    • 0 Attachment
      2match has been set and is working.

      :echo matcharg(2)[1] returns the correct pattern.

      Why does this not set the search register?

      let @/=matcharg(2)[1]

      matcharg({nr}) *matcharg()*
      Selects the {nr} match item, as set with a |:match|,
      |:2match| or |:3match| command.
      Return a |List| with two elements:
      The name of the highlight group used
      The pattern used.

      --
      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
      ... It works for me. Are you setting @/ within a function and expecting that setting to persist after the function returns? That won t work because functions
      Message 2 of 13 , Jun 24, 2012
      • 0 Attachment
        On 2012-06-24, Bee wrote:
        > 2match has been set and is working.
        >
        > :echo matcharg(2)[1] returns the correct pattern.
        >
        > Why does this not set the search register?
        >
        > let @/=matcharg(2)[1]

        It works for me.

        Are you setting @/ within a function and expecting that setting to
        persist after the function returns? That won't work because
        functions use their own instances of @/.

        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
      • Bee
        ... Thank you, I now see from :help / 9. Last search pattern register / *quote_/* *quote/* ... Note that the valued is restored when returning from a
        Message 3 of 13 , Jun 24, 2012
        • 0 Attachment
          On Jun 24, 10:32 am, Gary Johnson <garyj...@...> wrote:
          > On 2012-06-24, Bee wrote:
          > > 2match has been set and is working.
          >
          > > :echo matcharg(2)[1] returns the correct pattern.
          >
          > > Why does this not set the search register?
          >
          > > let @/=matcharg(2)[1]
          >
          > It works for me.
          >
          > Are you setting @/ within a function and expecting that setting to
          > persist after the function returns?  That won't work because
          > functions use their own instances of @/.
          >
          > Regards,
          > Gary


          Thank you, I now see from :help "/

          9. Last search pattern register "/ *quote_/* *quote/*
          ...
          "Note that the valued is restored when returning from a function"

          --And--

          *function-search-undo*
          The last used search pattern and the redo command "."
          will not be changed by the function. This also
          implies that the effect of |:nohlsearch| is undone
          when the function returns.

          BUT...

          When the following function exits, the '/' register is still set as it
          was in the function and 'n' will find the next occurance.
          What should it have been restored to?

          " toggle match end of long lines
          hi OverLength NONE cterm=underline ctermbg=darkyellow
          function! OverLength(n)
          if matcharg(2)[0] == "OverLength"
          2match none OverLength
          else "!greater than nth virtual column :help \%>v
          let @/='\%>' . a:n . 'v.*'
          execute '2match OverLength /' . @/ . '/'
          endif
          endf

          --
          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
          ... I would expect it to be restored to whatever value it had before the OverLength() function was called. Are you sure that the / register was not already
          Message 4 of 13 , Jul 8, 2012
          • 0 Attachment
            On 2012-06-24, Bee wrote:
            > On Jun 24, 10:32 am, Gary Johnson wrote:
            > > On 2012-06-24, Bee wrote:
            > > > 2match has been set and is working.
            > >
            > > > :echo matcharg(2)[1] returns the correct pattern.
            > >
            > > > Why does this not set the search register?
            > >
            > > > let @/=matcharg(2)[1]
            > >
            > > It works for me.
            > >
            > > Are you setting @/ within a function and expecting that setting to
            > > persist after the function returns?  That won't work because
            > > functions use their own instances of @/.
            > >
            > > Regards,
            > > Gary
            >
            >
            > Thank you, I now see from :help "/
            >
            > 9. Last search pattern register "/ *quote_/* *quote/*
            > ...
            > "Note that the valued is restored when returning from a function"
            >
            > --And--
            >
            > *function-search-undo*
            > The last used search pattern and the redo command "."
            > will not be changed by the function. This also
            > implies that the effect of |:nohlsearch| is undone
            > when the function returns.
            >
            > BUT...
            >
            > When the following function exits, the '/' register is still set as it
            > was in the function and 'n' will find the next occurance.
            > What should it have been restored to?
            >
            > " toggle match end of long lines
            > hi OverLength NONE cterm=underline ctermbg=darkyellow
            > function! OverLength(n)
            > if matcharg(2)[0] == "OverLength"
            > 2match none OverLength
            > else "!greater than nth virtual column :help \%>v
            > let @/='\%>' . a:n . 'v.*'
            > execute '2match OverLength /' . @/ . '/'
            > endif
            > endf

            I would expect it to be restored to whatever value it had before the
            OverLength() function was called. Are you sure that the '/'
            register was not already set to that pattern before the function
            was called?

            If you can do this:

            1. :let @/= "hello"
            2. :call OverLength(40)
            3. :echo @/

            and see that the '/' no longer contains "hello", then you may have
            found a bug in Vim.

            BTW, according to ":help 2match", clearing the match is done with
            ":2match none"--the second argument is not needed and appears to be
            ignored.

            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
          • Bee
            ... % 40v.* Bill -- 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
            Message 5 of 13 , Jul 8, 2012
            • 0 Attachment
              On Jul 8, 3:33 pm, Gary Johnson <garyj...@...> wrote:
              > On 2012-06-24, Bee wrote:
              > > On Jun 24, 10:32 am, Gary Johnson wrote:
              > > > On 2012-06-24, Bee wrote:
              > > > > 2match has been set and is working.
              >
              > > > > :echo matcharg(2)[1] returns the correct pattern.
              >
              > > > > Why does this not set the search register?
              >
              > > > > let @/=matcharg(2)[1]
              >
              > > > It works for me.
              >
              > > > Are you setting @/ within a function and expecting that setting to
              > > > persist after the function returns? That won't work because
              > > > functions use their own instances of @/.
              >
              > > > Regards,
              > > > Gary
              >
              > > Thank you, I now see from :help "/
              >
              > > 9. Last search pattern register    "/                 *quote_/* *quote/*
              > > ...
              > > "Note that the valued is restored when returning from a function"
              >
              > > --And--
              >
              > > *function-search-undo*
              > > The last used search pattern and the redo command "."
              > > will not be changed by the function.  This also
              > > implies that the effect of |:nohlsearch| is undone
              > > when the function returns.
              >
              > > BUT...
              >
              > > When the following function exits, the '/' register is still set as it
              > > was in the function and 'n' will find the next occurance.
              > > What should it have been restored to?
              >
              > > " toggle match end of long lines
              > > hi OverLength NONE cterm=underline ctermbg=darkyellow
              > > function! OverLength(n)
              > >   if matcharg(2)[0] == "OverLength"
              > >     2match none OverLength
              > >   else "!greater than nth virtual column :help \%>v
              > >     let @/='\%>' . a:n . 'v.*'
              > >     execute '2match OverLength /' . @/ . '/'
              > >   endif
              > > endf
              >
              > I would expect it to be restored to whatever value it had before the
              > OverLength() function was called.  Are you sure that the '/'
              > register was not already set to that pattern before the function
              > was called?
              >
              > If you can do this:
              >
              >     1.  :let @/= "hello"
              >     2.  :call OverLength(40)
              >     3.  :echo @/
              >
              > and see that the '/' no longer contains "hello", then you may have
              > found a bug in Vim.
              >
              > BTW, according to ":help 2match", clearing the match is done with
              > ":2match none"--the second argument is not needed and appears to be
              > ignored.
              >
              > Regards,
              > Gary

              after executing:
              :call OverLength(40)

              :echo @/ returns:
              \%>40v.*

              Bill

              --
              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
            • Bee
              ... hello ... % 40v.* Bill -- You received this message from the vim_use maillist. Do not top-post! Type your reply below the text you are replying to. For
              Message 6 of 13 , Jul 8, 2012
              • 0 Attachment
                On Jul 8, 3:33 pm, Gary Johnson <garyj...@...> wrote:
                > On 2012-06-24, Bee wrote:
                > > On Jun 24, 10:32 am, Gary Johnson wrote:
                > > > On 2012-06-24, Bee wrote:
                > > > > 2match has been set and is working.
                >
                > > > > :echo matcharg(2)[1] returns the correct pattern.
                >
                > > > > Why does this not set the search register?
                >
                > > > > let @/=matcharg(2)[1]
                >
                > > > It works for me.
                >
                > > > Are you setting @/ within a function and expecting that setting to
                > > > persist after the function returns? That won't work because
                > > > functions use their own instances of @/.
                >
                > > > Regards,
                > > > Gary
                >
                > > Thank you, I now see from :help "/
                >
                > > 9. Last search pattern register    "/                 *quote_/* *quote/*
                > > ...
                > > "Note that the valued is restored when returning from a function"
                >
                > > --And--
                >
                > > *function-search-undo*
                > > The last used search pattern and the redo command "."
                > > will not be changed by the function.  This also
                > > implies that the effect of |:nohlsearch| is undone
                > > when the function returns.
                >
                > > BUT...
                >
                > > When the following function exits, the '/' register is still set as it
                > > was in the function and 'n' will find the next occurance.
                > > What should it have been restored to?
                >
                > > " toggle match end of long lines
                > > hi OverLength NONE cterm=underline ctermbg=darkyellow
                > > function! OverLength(n)
                > >   if matcharg(2)[0] == "OverLength"
                > >     2match none OverLength
                > >   else "!greater than nth virtual column :help \%>v
                > >     let @/='\%>' . a:n . 'v.*'
                > >     execute '2match OverLength /' . @/ . '/'
                > >   endif
                > > endf
                >
                > I would expect it to be restored to whatever value it had before the
                > OverLength() function was called.  Are you sure that the '/'
                > register was not already set to that pattern before the function
                > was called?
                >
                > If you can do this:
                >
                >     1.  :let @/= "hello"
                >     2.  :call OverLength(40)
                >     3.  :echo @/
                >
                > and see that the '/' no longer contains "hello", then you may have
                > found a bug in Vim.
                >
                > BTW, according to ":help 2match", clearing the match is done with
                > ":2match none"--the second argument is not needed and appears to be
                > ignored.
                >
                > Regards,
                > Gary

                To make it clearer:

                :let @/= "hello"

                :echo @/
                hello

                :call OverLength(40)

                :echo @/
                \%>40v.*

                Bill

                --
                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
                ... I just tried that myself, as I suppose I could have earlier, and I see the same thing. I even simplified the function to this: function! MyTest() let
                Message 7 of 13 , Jul 8, 2012
                • 0 Attachment
                  On 2012-07-08, Bee wrote:
                  > On Jul 8, 3:33 pm, Gary Johnson wrote:
                  > > On 2012-06-24, Bee wrote:
                  > > > On Jun 24, 10:32 am, Gary Johnson wrote:
                  > > > > On 2012-06-24, Bee wrote:
                  > > > > > 2match has been set and is working.
                  > >
                  > > > > > :echo matcharg(2)[1] returns the correct pattern.
                  > >
                  > > > > > Why does this not set the search register?
                  > >
                  > > > > > let @/=matcharg(2)[1]
                  > >
                  > > > > It works for me.
                  > >
                  > > > > Are you setting @/ within a function and expecting that setting to
                  > > > > persist after the function returns? That won't work because
                  > > > > functions use their own instances of @/.
                  > >
                  > > > > Regards,
                  > > > > Gary
                  > >
                  > > > Thank you, I now see from :help "/
                  > >
                  > > > 9. Last search pattern register    "/                 *quote_/* *quote/*
                  > > > ...
                  > > > "Note that the valued is restored when returning from a function"
                  > >
                  > > > --And--
                  > >
                  > > > *function-search-undo*
                  > > > The last used search pattern and the redo command "."
                  > > > will not be changed by the function.  This also
                  > > > implies that the effect of |:nohlsearch| is undone
                  > > > when the function returns.
                  > >
                  > > > BUT...
                  > >
                  > > > When the following function exits, the '/' register is still set as it
                  > > > was in the function and 'n' will find the next occurance.
                  > > > What should it have been restored to?
                  > >
                  > > > " toggle match end of long lines
                  > > > hi OverLength NONE cterm=underline ctermbg=darkyellow
                  > > > function! OverLength(n)
                  > > >   if matcharg(2)[0] == "OverLength"
                  > > >     2match none OverLength
                  > > >   else "!greater than nth virtual column :help \%>v
                  > > >     let @/='\%>' . a:n . 'v.*'
                  > > >     execute '2match OverLength /' . @/ . '/'
                  > > >   endif
                  > > > endf
                  > >
                  > > I would expect it to be restored to whatever value it had before the
                  > > OverLength() function was called.  Are you sure that the '/'
                  > > register was not already set to that pattern before the function
                  > > was called?
                  > >
                  > > If you can do this:
                  > >
                  > >     1.  :let @/= "hello"
                  > >     2.  :call OverLength(40)
                  > >     3.  :echo @/
                  > >
                  > > and see that the '/' no longer contains "hello", then you may have
                  > > found a bug in Vim.
                  > >
                  > > BTW, according to ":help 2match", clearing the match is done with
                  > > ":2match none"--the second argument is not needed and appears to be
                  > > ignored.
                  > >
                  > > Regards,
                  > > Gary
                  >
                  > To make it clearer:
                  >
                  > :let @/= "hello"
                  >
                  > :echo @/
                  > hello
                  >
                  > :call OverLength(40)
                  >
                  > :echo @/
                  > \%>40v.*
                  >
                  > Bill

                  I just tried that myself, as I suppose I could have earlier, and I
                  see the same thing. I even simplified the function to this:

                  function! MyTest()
                  let @/='world'
                  endfunction

                  and after calling MyTest(), the '/' register contains "world".

                  However, if I change the function to this:

                  function! MyTest()
                  /match
                  echo @/
                  endfunction

                  and call it, the cursor moves to the next occurrence of "match" in
                  the file and the string "match" is echoed to the command line, but
                  executing ':echo @/' displays "hello".

                  So it appears that setting the '/' register indirectly alters a
                  local copy, but setting it directly with :let also alters the global
                  copy. I think that's a bug.

                  The results were the same on versions 7.2.330 and 7.3.584, so it has
                  been like this for a while.

                  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
                • Bee
                  ... Thank you Gary, for looking at this. It has me looking further, found the histadd() function. I had been counting on the bug as it made it easy to
                  Message 8 of 13 , Jul 8, 2012
                  • 0 Attachment
                    On Jul 8, 6:44 pm, Gary Johnson <garyj...@...> wrote:
                    > On 2012-07-08, Bee wrote:
                    > > On Jul 8, 3:33 pm, Gary Johnson wrote:
                    > > > On 2012-06-24, Bee wrote:
                    > > > > On Jun 24, 10:32 am, Gary Johnson wrote:
                    > > > > > On 2012-06-24, Bee wrote:
                    > > > > > > 2match has been set and is working.
                    >
                    > > > > > > :echo matcharg(2)[1] returns the correct pattern.
                    >
                    > > > > > > Why does this not set the search register?
                    >
                    > > > > > > let @/=matcharg(2)[1]
                    >
                    > > > > > It works for me.
                    >
                    > > > > > Are you setting @/ within a function and expecting that setting to
                    > > > > > persist after the function returns? That won't work because
                    > > > > > functions use their own instances of @/.
                    >
                    > > > > > Regards,
                    > > > > > Gary
                    >
                    > > > > Thank you, I now see from :help "/
                    >
                    > > > > 9. Last search pattern register "/ *quote_/* *quote/*
                    > > > > ...
                    > > > > "Note that the valued is restored when returning from a function"
                    >
                    > > > > --And--
                    >
                    > > > > *function-search-undo*
                    > > > > The last used search pattern and the redo command "."
                    > > > > will not be changed by the function. This also
                    > > > > implies that the effect of |:nohlsearch| is undone
                    > > > > when the function returns.
                    >
                    > > > > BUT...
                    >
                    > > > > When the following function exits, the '/' register is still set as it
                    > > > > was in the function and 'n' will find the next occurance.
                    > > > > What should it have been restored to?
                    >
                    > > > > " toggle match end of long lines
                    > > > > hi OverLength NONE cterm=underline ctermbg=darkyellow
                    > > > > function! OverLength(n)
                    > > > > if matcharg(2)[0] == "OverLength"
                    > > > > 2match none OverLength
                    > > > > else "!greater than nth virtual column :help \%>v
                    > > > > let @/='\%>' . a:n . 'v.*'
                    > > > > execute '2match OverLength /' . @/ . '/'
                    > > > > endif
                    > > > > endf
                    >
                    > > > I would expect it to be restored to whatever value it had before the
                    > > > OverLength() function was called. Are you sure that the '/'
                    > > > register was not already set to that pattern before the function
                    > > > was called?
                    >
                    > > > If you can do this:
                    >
                    > > > 1. :let @/= "hello"
                    > > > 2. :call OverLength(40)
                    > > > 3. :echo @/
                    >
                    > > > and see that the '/' no longer contains "hello", then you may have
                    > > > found a bug in Vim.
                    >
                    > > > BTW, according to ":help 2match", clearing the match is done with
                    > > > ":2match none"--the second argument is not needed and appears to be
                    > > > ignored.
                    >
                    > > > Regards,
                    > > > Gary
                    >
                    > > To make it clearer:
                    >
                    > > :let @/= "hello"
                    >
                    > > :echo @/
                    > > hello
                    >
                    > > :call OverLength(40)
                    >
                    > > :echo @/
                    > > \%>40v.*
                    >
                    > > Bill
                    >
                    > I just tried that myself, as I suppose I could have earlier, and I
                    > see the same thing.  I even simplified the function to this:
                    >
                    >     function! MyTest()
                    >       let @/='world'
                    >     endfunction
                    >
                    > and after calling MyTest(), the '/' register contains "world".
                    >
                    > However, if I change the function to this:
                    >
                    >     function! MyTest()
                    >       /match
                    >       echo @/
                    >     endfunction
                    >
                    > and call it, the cursor moves to the next occurrence of "match" in
                    > the file and the string "match" is echoed to the command line, but
                    > executing ':echo @/' displays "hello".
                    >
                    > So it appears that setting the '/' register indirectly alters a
                    > local copy, but setting it directly with :let also alters the global
                    > copy.  I think that's a bug.
                    >
                    > The results were the same on versions 7.2.330 and 7.3.584, so it has
                    > been like this for a while.
                    >
                    > Regards,
                    > Gary

                    Thank you Gary, for looking at this.
                    It has me looking further, found the histadd() function.

                    I had been counting on the 'bug' as it made it easy to continue
                    searching for long lines.

                    Now with histadd() this function adds the long line search to the
                    search history.

                    And... THAT is something I wanted to know how to do!

                    It can also workaround the 'bug' if need be:

                    function! OverLength(n)
                    if matcharg(2)[0] == "OverLength"
                    2match none
                    else "!greater than nth virtual column :help \%>v
                    let @/ = '\%>' . a:n . 'v.*'
                    call histadd("search",@/)
                    execute '2match OverLength /' . @/ . '/'
                    let @/ = histget("search", -2)
                    endif
                    endf

                    --OR--

                    This is what I had originally wanted to do,
                    but did not know how to save to the search history.

                    function! OverLength(n)
                    if matcharg(2)[0] == "OverLength"
                    2match none
                    else "!greater than nth virtual column :help \%>v
                    let there = '\%>' . a:n . 'v.*'
                    call histadd("search",there)
                    execute '2match OverLength /' . there . '/'
                    endif
                    endf

                    Bill

                    --
                    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
                  • Bee
                    ... Hi Gary Will you be writing a bug report? Or shall I? Where to post? vim_use or vim_dev Bill -- You received this message from the vim_use maillist. Do
                    Message 9 of 13 , Jul 9, 2012
                    • 0 Attachment
                      On Jul 8, 6:44 pm, Gary Johnson <garyj...@...> wrote:
                      > On 2012-07-08, Bee wrote:
                      > > On Jul 8, 3:33 pm, Gary Johnson wrote:
                      > > > On 2012-06-24, Bee wrote:
                      > > > > On Jun 24, 10:32 am, Gary Johnson wrote:
                      > > > > > On 2012-06-24, Bee wrote:
                      > > > > > > 2match has been set and is working.
                      >
                      > > > > > > :echo matcharg(2)[1] returns the correct pattern.
                      >
                      > > > > > > Why does this not set the search register?
                      >
                      > > > > > > let @/=matcharg(2)[1]
                      >
                      > > > > > It works for me.
                      >
                      > > > > > Are you setting @/ within a function and expecting that setting to
                      > > > > > persist after the function returns? That won't work because
                      > > > > > functions use their own instances of @/.
                      >
                      > > > > > Regards,
                      > > > > > Gary
                      >
                      > > > > Thank you, I now see from :help "/
                      >
                      > > > > 9. Last search pattern register "/ *quote_/* *quote/*
                      > > > > ...
                      > > > > "Note that the valued is restored when returning from a function"
                      >
                      > > > > --And--
                      >
                      > > > > *function-search-undo*
                      > > > > The last used search pattern and the redo command "."
                      > > > > will not be changed by the function. This also
                      > > > > implies that the effect of |:nohlsearch| is undone
                      > > > > when the function returns.
                      >
                      > > > > BUT...
                      >
                      > > > > When the following function exits, the '/' register is still set as it
                      > > > > was in the function and 'n' will find the next occurance.
                      > > > > What should it have been restored to?
                      >
                      > > > > " toggle match end of long lines
                      > > > > hi OverLength NONE cterm=underline ctermbg=darkyellow
                      > > > > function! OverLength(n)
                      > > > > if matcharg(2)[0] == "OverLength"
                      > > > > 2match none OverLength
                      > > > > else "!greater than nth virtual column :help \%>v
                      > > > > let @/='\%>' . a:n . 'v.*'
                      > > > > execute '2match OverLength /' . @/ . '/'
                      > > > > endif
                      > > > > endf
                      >
                      > > > I would expect it to be restored to whatever value it had before the
                      > > > OverLength() function was called. Are you sure that the '/'
                      > > > register was not already set to that pattern before the function
                      > > > was called?
                      >
                      > > > If you can do this:
                      >
                      > > > 1. :let @/= "hello"
                      > > > 2. :call OverLength(40)
                      > > > 3. :echo @/
                      >
                      > > > and see that the '/' no longer contains "hello", then you may have
                      > > > found a bug in Vim.
                      >
                      > > > BTW, according to ":help 2match", clearing the match is done with
                      > > > ":2match none"--the second argument is not needed and appears to be
                      > > > ignored.
                      >
                      > > > Regards,
                      > > > Gary
                      >
                      > > To make it clearer:
                      >
                      > > :let @/= "hello"
                      >
                      > > :echo @/
                      > > hello
                      >
                      > > :call OverLength(40)
                      >
                      > > :echo @/
                      > > \%>40v.*
                      >
                      > > Bill
                      >
                      > I just tried that myself, as I suppose I could have earlier, and I
                      > see the same thing.  I even simplified the function to this:
                      >
                      >     function! MyTest()
                      >       let @/='world'
                      >     endfunction
                      >
                      > and after calling MyTest(), the '/' register contains "world".
                      >
                      > However, if I change the function to this:
                      >
                      >     function! MyTest()
                      >       /match
                      >       echo @/
                      >     endfunction
                      >
                      > and call it, the cursor moves to the next occurrence of "match" in
                      > the file and the string "match" is echoed to the command line, but
                      > executing ':echo @/' displays "hello".
                      >
                      > So it appears that setting the '/' register indirectly alters a
                      > local copy, but setting it directly with :let also alters the global
                      > copy.  I think that's a bug.
                      >
                      > The results were the same on versions 7.2.330 and 7.3.584, so it has
                      > been like this for a while.
                      >
                      > Regards,
                      > Gary

                      Hi Gary

                      Will you be writing a bug report?
                      Or shall I?
                      Where to post? vim_use or vim_dev

                      Bill

                      --
                      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
                      ... Either works for me. I was waiting a while to see if anyone more knowledgeable might make some comment about it, but I think this discussion has been
                      Message 10 of 13 , Jul 9, 2012
                      • 0 Attachment
                        On 2012-07-09, Bee wrote:

                        > Will you be writing a bug report?
                        > Or shall I?
                        > Where to post? vim_use or vim_dev

                        Either works for me. I was waiting a while to see if anyone more
                        knowledgeable might make some comment about it, but I think this
                        discussion has been going long enough that anyone with anything to
                        add would have commented by now.

                        Bug reports go to vim_dev.

                        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
                      • Andy Wokula
                        ... ... also checked with 7.0 and 6.4 -- same results. I d say please don t declare this a bug, rather update the help. e.g. how would you otherwise clear the
                        Message 11 of 13 , Jul 9, 2012
                        • 0 Attachment
                          Am 09.07.2012 03:44, schrieb Gary Johnson:
                          >>>> 9. Last search pattern register "/ *quote_/* *quote/*
                          >>>> ...
                          >>>> "Note that the valued is restored when returning from a function"
                          >>>
                          >>>> --And--
                          >>>
                          >>>> *function-search-undo*
                          >>>> The last used search pattern and the redo command "."
                          >>>> will not be changed by the function. This also
                          >>>> implies that the effect of |:nohlsearch| is undone
                          >>>> when the function returns.
                          >>>
                          >>>> BUT...
                          >
                          > function! MyTest()
                          > let @/='world'
                          > endfunction
                          >
                          > and after calling MyTest(), the '/' register contains "world".
                          >
                          > However, if I change the function to this:
                          >
                          > function! MyTest()
                          > /match
                          > echo @/
                          > endfunction
                          >
                          > and call it, the cursor moves to the next occurrence of "match" in
                          > the file and the string "match" is echoed to the command line, but
                          > executing ':echo @/' displays "hello".
                          >
                          > So it appears that setting the '/' register indirectly alters a
                          > local copy, but setting it directly with :let also alters the global
                          > copy. I think that's a bug.
                          >
                          > The results were the same on versions 7.2.330 and 7.3.584, so it has
                          > been like this for a while.

                          ... also checked with 7.0 and 6.4 -- same results.

                          I'd say please don't declare this a bug, rather update the help.

                          e.g. how would you otherwise clear the last search pattern
                          :let @/ = ""
                          from within a function? (maybe not the best example)

                          Usually, when you assign to @/, you're supposed to know what you are
                          doing. OTOH, when doing a range command :/pat/ or :substitute or :global
                          etc. you might not think about side effects, that's what search-undo is for.

                          Plugins like :LogiPat assign to @/ within a function ().

                          Just to mention it, there is also a search-undo for autocmds.

                          --
                          Andy

                          --
                          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
                        • Bee
                          ... I agree with Andy, I would not call it a program bug, but a need to clarify the help. I like the fact that it is NOT reset on leaving a function. Bill --
                          Message 12 of 13 , Jul 9, 2012
                          • 0 Attachment
                            On Jul 9, 10:50 am, Andy Wokula <anw...@...> wrote:
                            > Am 09.07.2012 03:44, schrieb Gary Johnson:
                            >
                            >
                            >
                            >
                            >
                            > >>>> 9. Last search pattern register    "/                 *quote_/* *quote/*
                            > >>>> ...
                            > >>>> "Note that the valued is restored when returning from a function"
                            >
                            > >>>> --And--
                            >
                            > >>>> *function-search-undo*
                            > >>>> The last used search pattern and the redo command "."
                            > >>>> will not be changed by the function.  This also
                            > >>>> implies that the effect of |:nohlsearch| is undone
                            > >>>> when the function returns.
                            >
                            > >>>> BUT...
                            >
                            > >      function! MyTest()
                            > >        let @/='world'
                            > >      endfunction
                            >
                            > > and after calling MyTest(), the '/' register contains "world".
                            >
                            > > However, if I change the function to this:
                            >
                            > >      function! MyTest()
                            > >        /match
                            > >        echo @/
                            > >      endfunction
                            >
                            > > and call it, the cursor moves to the next occurrence of "match" in
                            > > the file and the string "match" is echoed to the command line, but
                            > > executing ':echo @/' displays "hello".
                            >
                            > > So it appears that setting the '/' register indirectly alters a
                            > > local copy, but setting it directly with :let also alters the global
                            > > copy.  I think that's a bug.
                            >
                            > > The results were the same on versions 7.2.330 and 7.3.584, so it has
                            > > been like this for a while.
                            >
                            > ... also checked with 7.0 and 6.4 -- same results.
                            >
                            > I'd say please don't declare this a bug, rather update the help.
                            >
                            > e.g. how would you otherwise clear the last search pattern
                            >      :let @/ = ""
                            > from within a function?  (maybe not the best example)
                            >
                            > Usually, when you assign to @/, you're supposed to know what you are
                            > doing.  OTOH, when doing a range command :/pat/  or :substitute or :global
                            > etc. you might not think about side effects, that's what search-undo is for.
                            >
                            > Plugins like :LogiPat assign to @/ within a function ().
                            >
                            > Just to mention it, there is also a search-undo for autocmds.
                            >
                            > --
                            > Andy

                            I agree with Andy, I would not call it a program bug, but a need to
                            clarify the help.

                            I like the fact that it is NOT reset on leaving a function.

                            Bill

                            --
                            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
                            ... I agree that the current behavior is not really a problem except that it differs from the documented behavior. I took a look through the source code. It
                            Message 13 of 13 , Jul 9, 2012
                            • 0 Attachment
                              On 2012-07-09, Bee wrote:
                              > On Jul 9, 10:50 am, Andy Wokula wrote:
                              > > Am 09.07.2012 03:44, schrieb Gary Johnson:

                              > > >>>> 9. Last search pattern register    "/                 *quote_/* *quote/*
                              > > >>>> ...
                              > > >>>> "Note that the valued is restored when returning from a function"
                              > >
                              > > >>>> --And--
                              > >
                              > > >>>> *function-search-undo*
                              > > >>>> The last used search pattern and the redo command "."
                              > > >>>> will not be changed by the function.  This also
                              > > >>>> implies that the effect of |:nohlsearch| is undone
                              > > >>>> when the function returns.
                              > >
                              > > >>>> BUT...
                              > >
                              > > >      function! MyTest()
                              > > >        let @/='world'
                              > > >      endfunction
                              > >
                              > > > and after calling MyTest(), the '/' register contains "world".
                              > >
                              > > > However, if I change the function to this:
                              > >
                              > > >      function! MyTest()
                              > > >        /match
                              > > >        echo @/
                              > > >      endfunction
                              > >
                              > > > and call it, the cursor moves to the next occurrence of "match" in
                              > > > the file and the string "match" is echoed to the command line, but
                              > > > executing ':echo @/' displays "hello".
                              > >
                              > > > So it appears that setting the '/' register indirectly alters a
                              > > > local copy, but setting it directly with :let also alters the global
                              > > > copy.  I think that's a bug.
                              > >
                              > > > The results were the same on versions 7.2.330 and 7.3.584, so it has
                              > > > been like this for a while.
                              > >
                              > > ... also checked with 7.0 and 6.4 -- same results.
                              > >
                              > > I'd say please don't declare this a bug, rather update the help.
                              > >
                              > > e.g. how would you otherwise clear the last search pattern
                              > >      :let @/ = ""
                              > > from within a function?  (maybe not the best example)
                              > >
                              > > Usually, when you assign to @/, you're supposed to know what you are
                              > > doing.  OTOH, when doing a range command :/pat/  or :substitute or :global
                              > > etc. you might not think about side effects, that's what search-undo is for.
                              > >
                              > > Plugins like :LogiPat assign to @/ within a function ().
                              > >
                              > > Just to mention it, there is also a search-undo for autocmds.
                              > >
                              > > --
                              > > Andy
                              >
                              > I agree with Andy, I would not call it a program bug, but a need to
                              > clarify the help.
                              >
                              > I like the fact that it is NOT reset on leaving a function.

                              I agree that the current behavior is not really a problem except
                              that it differs from the documented behavior.

                              I took a look through the source code. It appears that the current
                              behavior is intentional. See

                              set_last_search_pat()

                              and where it is called from

                              write_reg_contents_ex()

                              Are *quote/* and *function-search-undo* the only places where this
                              behavior is documented?

                              How about changing the note at the end of *quote/* to this:

                              Note that the value is restored when returning from a function
                              unless the value was set within the function using `:let`
                              |function-search-undo|.

                              and changing the first sentence of *function-search-undo* to this:

                              The redo command "." will not be changed by the function.
                              When the function returns, the last used search pattern will be
                              restored to what it was before the function was called unless
                              the search pattern was set within the function with `:let`.

                              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
                            Your message has been successfully submitted and would be delivered to recipients shortly.