2

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

  • Does replacing <return> with <cr> work? – EvergreenTree Dec 16 '15 at 17:53
  • 9
    See :h map-silent – VanLaser Dec 16 '15 at 18:26
  • Great, using <silent> does it! – jpmath 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
4

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

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