KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
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 endfunction 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 endfunction 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 endfunction function setUnnamedRegsiter() python <<EOF s = "Some \"crazy\" string\nwith interesting characters" vim.setRegister('@',s) EOF endfunction Or even a nice version of myescapefn I could use then that would be very handy. UPDATE: Based on the solution by ZyX I'm using this piece of python def setRegister(reg, value): vim.command( "let @%s='%s'" % (reg, value.replace("'","''") ) )
Tags (comma-separated)
Save Edits
Cancel