Monday, August 23, 2010

Re: if version >= 700 "?vim6.2 and for

On Aug 23, 8:28 am, Ben Fritz <fritzophre...@gmail.com> wrote:
> On Aug 20, 1:33 pm, Bee <200...@calcentral.com> wrote:
> > I have a .vimrc that is used for vim6.2 thru vim7.3 on Mac Terminal
> > This works to eliminate errror messages for the older vim6.2:
>
> > if version >= 700 "?vim6.2
> > ...
> > endif
>
> > EXCEPT with a new script which has a FOR ... ENDFOR
>
> > The ENDFOR seems to confused the IF.
>
> > Is there a workaround?
> > I suppose I could rewrite the script using WHILE
>
> A workaround that immediately presents itself to me, but seems a
> terrible way to accomplish it:
>
> if v:version >= 700
>   source somefilewithaforloop.vim
> endif
>
> Potentially, if you can construct the script in such a way that this
> actually works for you, you can put the for loop at the end of the
> file, and :finish whenever v:version < 700 before reaching the :for
> loop.
>
> Or just use :while as you suggest.

Thank you, I like insights like this, I have not used "source".
The simple solution I used was to recode using "while" as follows:

if version >= 700 "?vim6.2 printf "?tiny function
function Encode(str)
let out = ''
let i = 0
while i < strlen(a:str)
let c = a:str[i]
let n = char2nr(c)
let r = Urndm(0,8)
if r < 3 && c != '@' && c != '.'
let e = c
elseif r < 6
let e = printf("&#%d;",n)
else
let e = printf("&#x%x;",n)
endif
let out = out . e
let i += 1
endwhile
return out
endfun

function ReplaceWithEncoding()
let save = @@
normal! gvy
let @/ = @@
'<,'>s//\=Encode(@@)/
normal! `<
let @@ = save
endfun

vmap <F5> :call ReplaceWithEncoding()<cr>
endif

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