0

For example, I want to use default arguments:

function! MakeOrgTable(...)
let l:num_col = a:0 > 0? (a:0) :  0;
python << EOF
import vim
vim.current.buffer[:]=make_table(vim.current.buffer, vim.eval("l:num_col"))
EOF
endfunction

But it doesn't work, Vim cannot find l:num_col. But I do not want define a global variable like g:num_col.

So is there a way to pass local variables in a vimscript function to Python?

I use neovim 0.8.0.

3
  • 1
    Is the solution proposed addressing your problem? How can we help you more? Commented Feb 12, 2023 at 17:41
  • @VivianDeSmedt Thank you! Your answer is the solution. I'm sorry that I procrastinated. Commented Feb 13, 2023 at 14:41
  • Thanks for the feedback :-) No worries I was just verifying that your need were understood. Commented Feb 13, 2023 at 15:54

1 Answer 1

1

I believe the problem is related to trailing ; in the definition of l:num_col

I would do:

function! MakeOrgTable(...)
let l:num_col = a:0 > 0 ? (a:0) : 0
python << EOF
import vim
vim.current.buffer[:]=make_table(vim.current.buffer, vim.eval("l:num_col"))
EOF
endfunction

Another problem is that the method make_table is not defined.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.