On 11/12/2011 03:02 PM, AK wrote:
>>> command('let @a = "abc"')   -ak
>>
>> Let's assume I'd like to do something like.
>>
>> reg = vim.eval('@0')
>> reg.replace('a','A')
>> vim.command('let @a = "%s"' % reg)
>>
>> This will fail if reg contains funny characters.
>> I think I need something like
>>
>> vim.command('let @a = "%s"' % vim_escape_function(reg))
>>
>> What are the rules to escape characters (or is there a
>> commodity function)?
>>
> Try single instead of double quotes.  -ak

Python doesn't make a difference between single and double quotes,
so I assume you  talk about replacing the single quioes within the vim
command.

Do you mean like this??

vim.command("let @a = '%s'" % vim_escape_function(reg))

Let's assume the register contained four characters "A" "B" "'" and "C"

Then python would construct the string
let @a = 'AB'C' , pass it to vim (and vim would fail)

Let's assume

the register would contain following string (the text between the double
quotes:

"ABC'
let @b = 'DEF"

Then python would construct following comand (text betwwen double quotes)

"let @a = 'ABC'
let @b = 'DEF'"

which would set two registers (That's almost like SQL injection)

This is why I wondered whether  there is either
- a direct command in the python vim library, that
        allows to set a register,
- or whether there is a python commodity function to do proper
        escaping before calling vim.command()
- or whether there is a document explaining how to escape
        arbitrary characters in a string, such, that I can assign
        this string to a register.


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" )



-- 
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

Reply via email to