Hi,

John Beckett wrote:
> I want some Vim script to remove percent encoding (where '%'
> followed by two hex digits means the single character with the
> given hex ASCII code, for example '%412' is 'A2').
> 
> It's easy to do this using :substitute with:
> 
> :s/%\(\x\x\)/\=nr2char('0x'.submatch(1))/g
> 
> However, submatch() does not work in substitute(), and
> '\1' cannot be passed to a function (I think).
> 
> I would like either of the following to show 'abcAdef':
> 
> :echo substitute('abc%41def', '%\(\x\x\)', nr2char('0x'.submatch(1)), 'g')
> 
> :echo substitute('abc%41def', '%\(\x\x\)', nr2char('0x\1'), 'g')
> 
> But submatch() and \1 do not work here.
> 
> How can a submatch be used in an expression in substitute()?

you can use \= in substitute():

  :echo substitute('abc%41def', '%\(\x\x\)', '\=nr2char("0x".submatch(1))', 'g')

Regards,
Jürgen

-- 
Sometimes I think the surest sign that intelligent life exists elsewhere
in the universe is that none of it has tried to contact us.     (Calvin)

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