mack1885 / vim

Automatically exported from code.google.com/p/vim
0 stars 0 forks source link

v:hlsearch doesn't work when in a function. #380

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?

1. create a function:

  function! X()
    let @/ = 'test'
    let v:hlsearch = 1
  endfunction

2. given that `set hlsearch` is set, call the function,

What is the expected output? What do you see instead?
Was expected that the words `test` get highlight on all buffers, but doesn't 
work.

PS.: If I execute those `let` commands, without a function, it works.

What version of the product are you using? On what operating system?

VIM - Vi IMproved 7.4 (2013 Aug 10, compiled May 11 2015 14:26:15)
MacOS X (unix) version
Included patches: 1-728

Original issue reported on code.google.com by kassiobo...@gmail.com on 8 Jul 2015 at 12:33

GoogleCodeExporter commented 9 years ago
This is done on purpose: the highlighting state is saved and restored for a user
function, see ':help :nohlsearch' and ':help function-search-undo'.

I believe this is done so that the user's last search state is not accidentally
changed by functions (or autocommands), which may do searches just to do their 
work.

This is not documented in ':help v:hlsearch', but the help for :nohlsearch is 
linked
from there.

Also, the documentation for @" mentions this: ':help "/', or a bit above ':help 
@/'.

Not sure if this is a bug.

Maybe the v:hlsearch documentation should more clearly point this out? As in the
help for v:searchforward, which points this out and links to 
'function-search-undo'.

Also, are you asking for a way to force setting the search state from a 
function?

Original comment by odabr...@gmail.com on 8 Jul 2015 at 1:37

GoogleCodeExporter commented 9 years ago
Correction: please replace @" in the last comment with @/.

Original comment by odabr...@gmail.com on 8 Jul 2015 at 1:44

GoogleCodeExporter commented 9 years ago
Yeah, I guess improve g:hlsearch would be enough.
Thank you for the clarification. 

Original comment by kassiobo...@gmail.com on 8 Jul 2015 at 1:47

GoogleCodeExporter commented 9 years ago
This patch adds two lines to the docs of v:hlsearch.

Original comment by odabr...@gmail.com on 8 Jul 2015 at 2:45

Attachments:

GoogleCodeExporter commented 9 years ago
Thank you!

Original comment by kassiobo...@gmail.com on 8 Jul 2015 at 2:47

GoogleCodeExporter commented 9 years ago
I'll include the patch, thanks.

Original comment by brammool...@gmail.com on 8 Jul 2015 at 7:33