Can you access registers from python functions in vim
- by Michael Anderson
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.