I like having hlsearch on, but find it annoying in insert mode. So I tried doing the following autocommand to disable it whenever I enter insert mode:

autocmd InsertEnter * nohlsearch

For whatever reason, this does not work. So that I could verify this wasn't a problem with my .vimrc, I tried this after launching vim with

gvim -u NORC

Any help debugging this would be greatly appreciated! I'm using gvim version 7.4.1023 on windows.

  • Did you gave a colon after * symbol, like * :no?
    – SibiCoder
    Aug 22, 2016 at 4:18

1 Answer 1


:nohlsearch doesn't work inside an autocommand, as explained in :help :nohlsearch:

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. Same thing for when invoking a user function.

In vim-cool, I worked around that "issue" by using :set nohlsearch.

  • Thanks for this. I can't believe the answer was right there in help, and I missed it. Also, thanks for the plugin recommendation!
    – DJMcMayhem
    Aug 22, 2016 at 16:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.