Friday, March 30, 2012

Re: 'au InsertEnter * noh' doesn't work

On Friday, March 30, 2012 8:56:39 AM UTC-5, 蓝星灿 wrote:
> Hi everyone here, I'm just new to this mailing list.
> I want to automatically disable search highlight when entering insert
> mode, so I add the command in ~/.vimrc but it didn't work. Does anyone
> know what I did was wrong?

:help :nohlsearch


*:noh* *:nohlsearch*
:noh[lsearch] Stop the highlighting for the 'hlsearch' option. It
is automatically turned back on when using a search
command, or setting the 'hlsearch' option.
This command doesn't work in an autocommand, because
the highlighting state is saved and restored when
executing autocommands |autocmd-searchpat|.
Same thing for when invoking a user function.

Note the "this command doesn't work in an autocommand" text.

I think you can achieve your desired result, with one of these:

au InsertEnter * set nohlsearch
au InsertLeave * set hlsearch

OR

au InsertEnter * let s:sav_srch = @/ | let @/=""
au InsertLeave * let @/=s:sav_srch

(both untested)

--
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

No comments:

Post a Comment