Importing values from vim to python in vim9

51 views
Skip to first unread message

rameo

unread,
Dec 5, 2023, 2:28:02 PM12/5/23
to vim_use

I installed vim 9 but still have multiple functions written in old vimscript.

I've read that functions written in old vimscript still work.

However I noticed that importing variables into Python `vim.eval("a:myvariable")` no longer works

I don't always get the right values imported.

Example :

:call MyFunction("12", "14") 

function! MyFunction("variable1, variable2") 
python3 << endpython 
variable1 = vim.eval("a:variable1") 
variable2 = vim.eval("a:variable2") 
print(variable1 + " " + variable2) 
endpython 

endfunction

What's wrong in above code?

Or better... why doesn't it work anymore in vim9?

Christian Brabandt

unread,
Dec 5, 2023, 5:14:21 PM12/5/23
to vim...@googlegroups.com
Do you get an error message? Which one? If this doesn't work anymore,
when did it stop working?

Thanks,
Christian
--
Driver does not carry cash.

rameo

unread,
Dec 5, 2023, 6:04:30 PM12/5/23
to vim_use
No message. 
I noticed that the values are no longer correct. I am using the same function more and the values are not refreshed. Old values are kept.
I can't remember exactly when it stopped working. I noticed it today.

I just tested with this:
variable1 = str(vim.bindeval("a:variable1"))
variable2 = str(vim.bindeval("a:variable2"))


This works.

But now it's binary isn't it (b'value')? How do I get it as text again?
Isn't there a better solution?

Thanks,
Rameo

Salman Halim

unread,
Dec 5, 2023, 7:14:04 PM12/5/23
to Vim Users
I might be nitpicking, but why are the function parameters in the function definition in quotes?

Salman

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/ZW%2Bgsu3Q23sAczgm%40256bit.org.

rameo

unread,
Dec 6, 2023, 4:56:28 AM12/6/23
to vim_use
You are right. The variable names in the above example should be without quotes MyFunction(variable1, variable2) . 
In my functions, they are without quotes.
Reply all
Reply to author
Forward
0 new messages