Can you access registers from python functions in vim
Posted
by Michael Anderson
on Stack Overflow
See other posts from Stack Overflow
or by Michael Anderson
Published on 2010-04-23T00:29:59Z
Indexed on
2010/04/23
0:33 UTC
Read the original article
Hit count: 612
It seems vims python sripting is designed to edit buffer and files rather than work nicely with vims registers. You can use some of the vim packages commands to get access to the registers but its not pretty.
My solution for creating a vim function using python that uses a register is something like this.
function printUnnamedRegister()
python >> EOF
print vim.eval('@@')
EOF
Setting registers may also be possible using something like
function setUnnamedRegsiter()
python >> EOF
s = "Some \"crazy\" string\nwith interesting characters"
vim.command('let @@="%s"' % myescapefn(s) )
EOF
However this feels a bit cumbersome and I'm not sure exactly what myescapefn should be. So I've never been able to get the setting version to work properly.
So if there's a way to do something more like
function printUnnamedRegister()
python >> EOF
print vim.getRegister('@')
EOF
function setUnnamedRegsiter()
python >> EOF
s = "Some \"crazy\" string\nwith interesting characters"
vim.setRegister('@',s)
EOF
Or even a nice version of myescapefn I could use then that would be very handy.
© Stack Overflow or respective owner