Tuesday, April 24, 2012

RE: questions about submatch()

rameo wrote:
> If I use submatch like this:
> :%s/'pattern'/\=MyFunction(submatch())/g

That gives:
E119: Not enough arguments for function: submatch
E116: Invalid arguments for function MyFunction(submatch())

> I would like to confirm (with a "c" flag) all single
> substitutions but the "c" flag at the end of the substitution
> command (:%s/'pattern'/\=MyFunction(submatch())/gc) doesn't work.

The following works on my system:

function! MyFunction(m)
let x = len(a:m)
return x
endfunction
%s/'pattern'/\=MyFunction(submatch(0))/gc

Testing on following gave a confirm for each change.

'pattern' hello 'pattern' hello 'pattern' hello

John

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

No comments: