On 02/04/11 08:52, ZyX wrote:
Reply to message «Re: Problems using value returned by external command»,
sent 10:21:48 02 April 2011, Saturday
by Gary Johnson:

As you've figured out, Vim's system() function includes in its
return value the newline at the end of the command's output.  If you
need the result without the newline, use substitute() like this:

     let x = substitute(system("some command"), "\n", "", "")
This will remove all newlines, not just at the end. If one knows that command
will output newline at the end, then he should just use system(...)[:-2].

If a newline at the end is possible but not certain, and must be removed, just use (untested)

        substitute(system('foo bar baz'), '\n$', "", "")

where (IIUC)
\n (within single quotes) is passed unchanged to substitute() and *then* interpreted by it as a linefeed
        $ means end-of-string


Best regards,
Tony.
--
Stay away from flying saucers today.

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

Reply via email to