On Fri, 9 Mar 2012, Cesar Romani wrote:

On 09/03/2012 02:34 p.m., Tim Chase wrote:
On 03/09/12 13:11, Cesar Romani wrote:
On 09/03/2012 12:43 p.m., Tim Chase wrote:
%s/.*/\='['.toupper(submatch(0)).'](#'.substitute(tolower(submatch(0)), ' ', 
'-', 'g').')'
>
>  -tim

Thanks a lot, it works fine, but if I use it under :execute and try to convert:

Véase Vaya con Dios

to:

[VAYA CON DIOS](#vaya-con-dios)

there are some problems with quotes, as in:

execute '%s/Véase 
\(.*\)/\='['.toupper(submatch(1)).'](#'.substitute(tolower(submatch(1)), ' ', '-', 
'g').')'."'"

Is there any reason you're trying to do it with an :exec rather than just calling it directly?

Because I'm using it inside a function

Functions can execute commands directly.

fun! TestFunction()
    %s/Véase 
\(.*\)/\='['.toupper(submatch(1)).'](#'.substitute(tolower(submatch(1)), ' ', 
'-', 'g').')'
endf

You might also want to change \(.*\) to something more restrictive, and add the 'e' modifier to prevent an error if nothing matches:

fun! TestFunction()
    %s/Véase 
\(\w\+\%(\s\w\+\)*\)/\='['.toupper(submatch(1)).'](#'.substitute(tolower(submatch(1)),
 ' ', '-', 'g').')'/e
endf

--
Best,
Ben

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