Hi Zdenek,

On 5/5/06, Zdenek Sekera <[EMAIL PROTECTED]> wrote:
I have this problem (trivially simplified a real case):

let a="a\nb\nc"

When echo'ing it, it displays lines:

:echo a
a
b
c

Now I need to call system() and have the contents of 'a'
as the file, without actually writing the 'a' into a temp file,
something like this:

execute "system(". editor . " " . file .")"

where 'editor' is a variable containing the editor name,
could be

let editor=gvim

and 'file' is *the something* containing the lines from
the variable 'a'.

Can that be done or do I have to go via a temp file?


The system() function in Vim7 takes an additional optional argument that
specifies the input to a command:

----------------------------------------------------------------------------------------------------------
system({expr} [, {input}])                              *system()* *E677*
               Get the output of the shell command {expr}.
               When {input} is given, this string is written to a file and
               passed as stdin to the command.  The string is written as-is,
               you need to take care of using the correct line separators
               yourself.  Pipes are not used.
----------------------------------------------------------------------------------------------------------

In your example, you can do:

   call system(editor, a)

This will write the contents of the variable 'a' to a temporary file and
supply it to the command mentioned in the variable 'editor'.

- Yegappan

Reply via email to