Importing values from vim to python in vim9

瀏覽次數:51 次
跳到第一則未讀訊息

rameo

未讀,
2023年12月5日 下午2:28:022023/12/5
收件者: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

未讀,
2023年12月5日 下午5:14:212023/12/5
收件者: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

未讀,
2023年12月5日 下午6:04:302023/12/5
收件者: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

未讀,
2023年12月5日 晚上7:14:042023/12/5
收件者: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

未讀,
2023年12月6日 凌晨4:56:282023/12/6
收件者: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.
回覆所有人
回覆作者
轉寄
0 則新訊息