If I type:

:echoerr "test error"

I simply get the message printed (with red background):

test error

However, inside a function:

function! Printerror()
  echoerr "test error"

I get additional (and in this particular case) unwanted extra lines:

Error detected while processing function Printerror:
line    1:
test error
Press ENTER or type command to continue

How can I supress the additional lines produced in a function?

  • See also : h hit-enter and :h cmdheight
    – VanLaser
    Sep 25, 2016 at 10:15

1 Answer 1


The solution is described in the manual:

If you just want a highlighted message use :echohl. And to get a beep: :exe "normal \<Esc>"


function! PrintError(msg) abort
    execute 'normal! \<Esc>'
    echohl ErrorMsg
    echomsg a:msg
    echohl None
  • Hmm, why doesn't :echohl "foo" work in command mode?
    – Tom Hale
    Sep 25, 2016 at 10:35
  • 2
    @TomHale, because you didn't read :help :echohl. And it's "command-line mode", not "command mode".
    – romainl
    Sep 25, 2016 at 10:41

Your Answer

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

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