On Fr, 24 Nov 2017, Marius Gedminas wrote: > On Fri, Nov 24, 2017 at 11:30:03AM +0100, Christian Brabandt wrote: > > Hi, > > while writing the test for checking the URLs I stumbled on this > > difference between submatch(1) and \1: > > #v+ > > let a = ' https://www.vim.org ' > > let g:pat = '.\{-}\(http[^ ]*\).\{-}$' > > echo substitute(a, g:pat, submatch(1), '') > > echo substitute(a, g:pat, '\1', '') > > #v- > > > > If you execute this piece of script, the first map() returns an empty > > list, while the second map() returns the URL stripped by whitespace > > (which would be my expected behaviour for both map() calls). > > > > Is this expected? > > You're calling submatch(1) and then passing the returned value to > substitute(). > Try > > echo substitute(a, g:pat, '\=submatch(1)', '') > > or > > echo substitute(a, g:pat, {m->submatch(1)}, '') > > or > > echo substitute(a, g:pat, {m->m[1]}, '')
It is only valid in a expression context of the replace part in the substitute() function? That is not how I read the help. That should be stressed some more (or generate an error, if this is generally invalid perhaps?) Christian -- Warum läuft die Nase, während die Füße riechen? -- -- You received this message from the "vim_dev" 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 --- You received this message because you are subscribed to the Google Groups "vim_dev" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.
