Wednesday, December 23, 2009

Re: Best practice and enhance performance duration of vimscript

> I'm not sure what exactly you're trying to achieve here -- mostly the
> source of the l:lineToChange -- is this from some larger loop?  The
> reason it's confusing is that after you've gone through the loop once,
> I'd expect that TO_SUB_WITH_KEY is no longer in the string, so
> subsequent passes through the loop look like they're just appending the
> same line (which, btw, I'd perform with
>
>     put=line
>
> instead of via normal mode.)
>
> My first thought would be to do fewer substitutes, which could be done
> if your hashes are nested, so you have a double-dereferencing.
> Something like
>
>     :%s/TSWK1\|TSWK2\|TSWK3/\=s:hash[submatch(0)]/g
>
> or, if you have a bunch of keys, you might be able to do something like
>
>     :let @/=join(keys(s:hash), '\|')
>     :%s//\=s:hash[submatch[0]]/g
>
> (you might have to escape the keys if there are funky regexp
> metacharacter values in the hash keys)
>
> -tim

Tim, see my first post, l:lineToChange is defined before the loop that
is doing mapping.
In fact, I prefered concat my xml line before loop and doing mapping
(substitute) into the loop thinking it was faster.

I don't see exactly the soluce you submit to me but I explain the
current process.

I am defining a templateLine

l:lineToChange = '<xmltag
WORD_TO_SUBSTITUTE1foofoofoofoobarWORD_TO_SUBSTITUTE2foofofofofofofobarWORD_TO_SUBSTITUTE3/
>'


myHash[KEY]= {'word1':WORD1,'word2':WORD2,'word3':WORD3}

for key in keys(.....

Then in the loop on keys(myHash) I am doing substitutes that I need to
do (mapping no ?)

endfor

NB : I didn't know if exec 'norm o' take a long time, thank you for
your
response.

If you have other advises or link I will be glad to apply them.
Thank you Tim

--
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php

No comments:

Post a Comment