Tuesday, March 12, 2013

Re: Can I use split() on this?

On 2013-03-12 16:23, Cesar Romani wrote:
> How to convert from
> [uno\dos\tres](fijo)
>
> to
> [uno](fijo)
> [dos](fijo)
> [tres](fijo)

The most straightforward would be to do something like

%s/\[\([^]]*\)]\s*\((.*\)/\=join(map(split(submatch(1), '\\'), '"[" .
v:val . "]" . submatch(2)'), "\n")

(all on one line). I'm sure there's some way to do something like
one of the following which got me pretty close:

%s/\%(\[[^]]*\)\@<=\<\(\w\+\)\>\\\=\([^]]\+]\)\((.*\)/\1]\3\r[\2\3/g

%s/\%(\[[^]]*\)\@<=\zs\<\(\w\+\)\>\ze\%([^]]*]\((.*\)\)\=/\1]\2\r[/g

but neither was quite the results I was hoping for.

-tim


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

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

No comments: