How to have the echo command process newline characters?












1















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 "foonbar". I'm running gvim on windows










share|improve this question

























  • 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 '18 at 3:19













  • Ok I updated the question

    – Steve Vermeulen
    Dec 8 '18 at 3:25
















1















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 "foonbar". I'm running gvim on windows










share|improve this question

























  • 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 '18 at 3:19













  • Ok I updated the question

    – Steve Vermeulen
    Dec 8 '18 at 3:25














1












1








1








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 "foonbar". I'm running gvim on windows










share|improve this question
















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 "foonbar". I'm running gvim on windows







command-line echo






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Dec 8 '18 at 3:25







Steve Vermeulen

















asked Dec 8 '18 at 3:14









Steve VermeulenSteve Vermeulen

87789




87789













  • 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 '18 at 3:19













  • Ok I updated the question

    – Steve Vermeulen
    Dec 8 '18 at 3:25



















  • 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 '18 at 3:19













  • Ok I updated the question

    – Steve Vermeulen
    Dec 8 '18 at 3:25

















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 '18 at 3:19







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 '18 at 3:19















Ok I updated the question

– Steve Vermeulen
Dec 8 '18 at 3:25





Ok I updated the question

– Steve Vermeulen
Dec 8 '18 at 3:25










1 Answer
1






active

oldest

votes


















3














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 "foonbar"

:echon "foonbar"

: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 ^@).






share|improve this answer


























  • Ohh I didn't realize this behaviour was specific to echom. Thanks.

    – Steve Vermeulen
    Dec 8 '18 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 '18 at 8:38













Your Answer








StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "599"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fvi.stackexchange.com%2fquestions%2f18203%2fhow-to-have-the-echo-command-process-newline-characters%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









3














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 "foonbar"

:echon "foonbar"

: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 ^@).






share|improve this answer


























  • Ohh I didn't realize this behaviour was specific to echom. Thanks.

    – Steve Vermeulen
    Dec 8 '18 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 '18 at 8:38


















3














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 "foonbar"

:echon "foonbar"

: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 ^@).






share|improve this answer


























  • Ohh I didn't realize this behaviour was specific to echom. Thanks.

    – Steve Vermeulen
    Dec 8 '18 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 '18 at 8:38
















3












3








3







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 "foonbar"

:echon "foonbar"

: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 ^@).






share|improve this answer















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 "foonbar"

:echon "foonbar"

: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 ^@).







share|improve this answer














share|improve this answer



share|improve this answer








edited Dec 8 '18 at 3:47

























answered Dec 8 '18 at 3:38









B LayerB Layer

5,6771418




5,6771418













  • Ohh I didn't realize this behaviour was specific to echom. Thanks.

    – Steve Vermeulen
    Dec 8 '18 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 '18 at 8:38





















  • Ohh I didn't realize this behaviour was specific to echom. Thanks.

    – Steve Vermeulen
    Dec 8 '18 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 '18 at 8:38



















Ohh I didn't realize this behaviour was specific to echom. Thanks.

– Steve Vermeulen
Dec 8 '18 at 6:58





Ohh I didn't realize this behaviour was specific to echom. Thanks.

– Steve Vermeulen
Dec 8 '18 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 '18 at 8:38







@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 '18 at 8:38




















draft saved

draft discarded




















































Thanks for contributing an answer to Vi and Vim Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fvi.stackexchange.com%2fquestions%2f18203%2fhow-to-have-the-echo-command-process-newline-characters%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Le Mesnil-Réaume

Ida-Boy-Ed-Garten

web3.py web3.isConnected() returns false always