I find that when running :echo message with a message variable that contains newlines, it displays the newline character as ^@. Often I'd prefer it to actually be split on a new line though. Do I have to split up the string manually and then make multiple calls to echo or is there a simpler way to do that?

edit: Here's an example that reproduces what I'm talking about: :echom "foo\nbar". I'm running gvim on windows

  • Can you be more specific about those newlines. Where is the text coming from. Are you on *nix or Windows? (Can't be regular, multi-line Vim text because that should work just fine.) – B Layer Dec 8 at 3:19
  • Ok I updated the question – Steve Vermeulen Dec 8 at 3:25
up vote 3 down vote accepted

You originally mention :echo but based on your example it's :echom that is causing you issues so assuming that's right...

Some choices depending on your specific needs (e.g. do you care about the message being saved to the message history)...

:echo "foo\nbar"

:echon "foo\nbar"

:echom "foo" | echom "bar"

All of these will produce

foo
bar

Likely due to it's primary purpose being to print messages to be read by the user interactively, echom parses things a bit differently from the others. "Unprintable characters are displayed not interpreted". (Similar to the strtrans() function which also prints newlines as ^@).

  • Ohh I didn't realize this behaviour was specific to echom. Thanks. – Steve Vermeulen Dec 8 at 6:58
  • @SteveVermeulen No problem. Yeah I think the primary use case for echom, in contrast to the others, is real-time display of short messages for users. Thus you get qualities like avoiding non-printing chars and discouraging multi-line output. – B Layer Dec 8 at 8:38

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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