Meow
Meow

Reputation: 4561

How to pass arguments from vimscript functions to python interface?

For example, processing positional arguments:

function! Example(arg)
python <<_EOF_

# do something with a:arg

_EOF_
endfunction

or the ... list:

function! Example(...)
python <<_EOF_

# do something with a:000, a:1, a:2, etc.

_EOF_
endfunction

Is there anyway I can do this?

Upvotes: 13

Views: 2246

Answers (1)

Ingo Karkat
Ingo Karkat

Reputation: 172688

You can retrieve the function arguments just like any other Vimscript expression through vim.eval():

function! Example(arg)
python << _EOF_

import vim
print "arg is " + vim.eval("a:arg")

_EOF_
endfunction

Upvotes: 21

Related Questions