How would I do something like the following in vim:
echom "hello"
pyx print('New item')
let a = (pyx import socket; socket.gethostname())
echom a
The first and second lines work; but how to assign a variable name to a python value/output?
Import module vim and execute vim's command let passing value from Python:
:py3 import socket, vim; hn=socket.gethostname(); vim.command('let vim_hn="'+hn+ '"')
hn=… assigns a variable in Python; 'let vim_hn="'+hn+ '"' passes its value to command let; something like let vim_hn="myhost"; vim.command() executes that let from Python.
Now you can inspect the value in vim:
:echo vim_hn
no module named vim -- does this require an additional library to play nice with vim in python?py3 import socket; vim.command("let vim_hn='%s'" % socket.gethostname()) echom "The hostname is: " . vim_hnvim is only available in built-in Python, of course.I've experimented a few approaches
:let vimvar = pyxeval('PythonExpression') from vim code when possiblevim.command('let vimvar = ...') makes more sense, in particular from Python code.