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? Commented Dec 16, 2015 at 17:53
  • 9
    See :h map-silent
    – VanLaser
    Commented Dec 16, 2015 at 18:26
  • Great, using <silent> does it!
    – user5370
    Commented Dec 17, 2015 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
    Commented Jan 18, 2016 at 15:11
  • From my point, do it :)
    – VanLaser
    Commented Jan 18, 2016 at 15:18

1 Answer 1

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 and acknowledge you have read our privacy policy.