4

I am using

nnoremap <esc> :noh<return><esc>

to remove the highlighting after a search with hlsearch on.

Pressing <esc>, this shows :noh in the command line. I would like to turn this off (preferably without any side effects).

6
  • Does replacing <return> with <cr> work? Dec 16 '15 at 17:53
  • 9
    See :h map-silent
    – VanLaser
    Dec 16 '15 at 18:26
  • Great, using <silent> does it!
    – user5370
    Dec 17 '15 at 9:56
  • @VanLaser If neither of you adds this as an answer, I'm going to. (Having solved issues in "Unanswered" is untidy!)
    – Rich
    Jan 18 '16 at 15:11
  • From my point, do it :)
    – VanLaser
    Jan 18 '16 at 15:18
6

As @VanLaser mentions in a comment, you can do this by adding <silent> to your map command:

nnoremap <silent> <esc> :noh<return><esc>

:help :map-silent explains:

To define a mapping which will not be echoed on the command line, add "<silent>" as the first argument. Example:

:map <silent> ,h /Header<CR>

The search string will not be echoed when using this mapping. Messages from the executed command are still given though. To shut them up too, add a ":silent" in the executed command:

:map <silent> ,h :exe ":silent normal /Header\r"<CR>

Prompts will still be given, e.g., for inputdialog().

Using "<silent>" for an abbreviation is possible, but will cause redrawing of the command line to fail.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy