1

Is there a way to use a vimscript function to pass arguments to an external command?

I have the following:

function! GetJobLines(argA)

    " 1. Create a new buffer for the output
    enew

    " 2. Change directory to location of said script
    cd /home/leeand00/src

    " 3. Run said script with argument (not really but for example)
    read!echo a:argA
endfunction

I've also tried:

read!"echo" . a:argA
3

The usual way to incorporate the value of a variable into an Ex command is to use the :execute command, which concatenates its arguments into a string, then executes that string, like this:

:execute "read!echo" a:argA

or even better, like this, which includes the use of shellescape() to make sure that the characters of a:argA are properly quoted for use by the shell:

:execute "read!echo" shellescape(a:argA)

See

:help :execute
:help shellescape()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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