On Sun, Aug 13, 2006 at 01:04:23AM -0500, Bill McCarthy wrote:
> Hello Vim List,
>
> " odd result
> "
> " This is part of some code going into a "command". If the
> " left 3 columns are removed - making this code with 1
> " statement per line - the code works perfectly. [It sets
> " 'wfw' for all windows that can be reached with ":wincmd
> " l", then returns to the original window.]
> "
> " However, as is, it only works if there is a window to the
> " right of the current window. If there isn't, it errors
> " out with: E170: missing :endwhile
>
> let owin = winnr()
> \| let lwin = owin
> \| winc l
> \| let nwin = winnr()
> \| while nwin != lwin
> \| let w:owfw = &winfixwidth
> \| set wfw
> \| let lwin = nwin
> \| wincmd l
> \| let nwin = winnr()
> \| endwhile
> \| exec owin . 'wincmd w'
>
> " Can anyone help me get around this little misunderstanding
> " I am having with the Vim interpreter? (I know that I can
> " put this code into a function with 1 statement per line,
> " but I am curious as to why it will not work as is.)
It looks inconsistent to me. I tried a simplified version:
:let owin = winnr() | let lwin = owin | winc l | let nwin = winnr() | while
nwin != lwin | let lwin = nwin | wincmd l | let nwin = winnr() | endwhile
(all one line) and saw something similar: with only one window, vim
waits for more input, but it is fine after :vsplit . I decided I wanted
some feedback, so I added an :echo :
:let owin = winnr() | let lwin = owin | winc l | let nwin = winnr() | while
nwin != lwin | let lwin = nwin | wincmd l | let nwin = winnr() | endwhile |
echo "done"
(again, one llne). Now, vim waits for :endwhile whether or not I have
multiple windows.
I also tried
:let n = 0 | while n > 0 | let n = n-1 | endwhile | echo "n =" n
:let n = 1 | while n > 0 | let n = n-1 | endwhile | echo "n =" n
and both of these worked fine.
I remember something about not allowing :endwhile on the same line
as the :while , separated by | , but I cannot find it in the docs today.
HTH --Benji Fisher