0

I've enabled hlsearch to highlight text after searching,

$ grep hlsearch ~/.vimrc
set hlsearch

and now I want to clear the highlight, which I can do with :noh. I saw that I can assign this to esc key in normal mode with this:

$ grep noh ~/.vimrc
nnoremap <silent> <esc> :noh<cr><esc>

Now everytime I open vim, it opens in -- REPLACE -- mode. How can I fix this?

The version of vim:

$ vim --version
VIM - Vi IMproved 8.2 (2019 Dec 12, compiled Sep 15 2021 21:48:21)
Included patches: 1-3441
Compiled by Arch Linux
Huge version without GUI.
4
  • That mapping looks fine. Which version of Vim are you using? I tested this in Vim8.2.3364 with no problem. I even tried to add normal R at the end of my ~/.vimrc and Vim opened in NORMAL mode. Sep 28 '21 at 17:07
  • @ChrisHeithoff VIM - Vi IMproved 8.2 (2019 Dec 12, compiled Sep 15 2021 21:48:21) Sep 28 '21 at 17:08
  • 3
    Do not map <esc>! (at least not until Vim has finally started up) vi.stackexchange.com/a/2620/71 Sep 28 '21 at 17:51
  • @ChristianBrabandt I see. Thank you. Sep 28 '21 at 18:16

Browse other questions tagged or ask your own question.