On 11/12/2011 11:16 PM, Gelonida N wrote:
> On 11/12/2011 03:02 PM, AK wrote:
>
> If I rephrase my question for non python users:
>
> How can I write a vim command, that puts fuloowing five characters in
> register '0'
>
> single_quite, double_quote, escape, carriage_return, tab
>
> The escaped python string or above five characters would be.
> '\'"\x1b\n\t' ( or "'\"\x1b\n\t" )
>
>
>
I came up with following python function to set a register to an
arbitrar string.
The only thing that I do is to escape the double quote character.
However as I don't know vim scripting well enough I don't know whether
this will be sufficient for all weird characters, that might show up.
def setreg(regname, val):
""" sets register regname to string val
all it does is replace " with \"
and use the 'let' command to set a register
"""
val = val.replace('"',r'\"')
vim.command('let @%s = "%s"' % (regname, val))
def uppercase_a(regname):
""" sample command to show the use of setreg() """
reg_a = vim.eval('@' + regname)
reg_a = reg_a.replace('a', 'A')
setreg('a', reg_a)
With above python function I could now do
:py setreg('a', 'ABC"\'\tDEF\nGHI')
and register a would contain the string as specified in python.
Should this do the job or does anybody see potential improvements?
--
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