5

I have the following vimscript: it contains a vimscript function which executes a python code thanks to python << EOF:

function! Test(myArgument)
python << EOF
def test(myArgument):
    print "My argument " + myArgument

test("foo")
EOF
endfunction

How can I use the argument of the vimscript function a:myArgument and pass it as argument to my python function (instead of foo)?

5

You can use the vim package inside python, you should be able to gain access to vim:

function! Test(myArgument)
    python << EOF
import vim

def test(myArgument):
    print "My argument " + myArgument

test(vim.eval('a:myArgument'))
EOF
endfunction

You can read about the python integration at :h python and about this particular feature at :h python-eval.

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.