On Jul 9, 10:50 am, Andy Wokula <[email protected]> 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
