3

I found from the vim's manual that we can echo colored text by the following command:

:echohl WarningMsg | echo "Warnging" | echohl None | echo ":Some warning"

which will highlight the string Warning and keep :Some warning in default color. My problem is that this will display the results in two lines, is there any way to display them in one line?

4

This should work:

function! EchoWarning(msg)
  echohl WarningMsg
  echo "Warning"
  echohl None
  echon ': ' a:msg
endfunction

call EchoWarning('test')

This defined a simple function that you can call with the warning message as the argument.

As you see, the key is the echon command, which is similar to an echo except it does not add a newline at the end.

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.