Friday, February 14, 2014

Trimming newlines from calls to system()

When I echom something from the command line using system():

    :echom system("echo \"testing\"")

I get a ^@ (null) at the end of the result:

    testing^@

If I instead use echo, which doesn’t translate unprintable characters but displays them:

    :echo system("echo \"testing\")

I get the result of the command line command with an added newline:

    testing
    

This of course normally makes sense at the command line, but when I’m returning output taken from the command line as a Vim message I don’t want an unnecessary newline. I can eliminate it by returning the first item in a List made from split() used on the return value from system() with "\n" as the pattern (or perhaps by substitute-ing newlines with ''), but is there a simpler way to do this?

Thanks!

Ben

--
b

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
 
---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

No comments:

Post a Comment