Monday, March 26, 2012

Re: buggy behavior when changing 'virtualedit' inside scripts?

I apologize. I couldn't reproduce my problem either...because I
apparently left out a critical piece when condensing my much larger
example. The real problem seems to also involve 'opfunc'. If you
source the following function definitions and mappings, you will see
that -$ and +$ inexplicably behave differently.

I tested it on Vim 7.3 (with patches 1-244,246-462) on OS X (10.7) and
Vim 7.3 (with patches 1-62) on Linux (kernel 2.6). In both cases, I
ran vim in a terminal, using the command line "vim -u NONE -NX".

- Aaron

----
function Foo1(type)
set ve=onemore
silent execute "normal! `[v`]dix\e"
set ve=
endfunction

function Foo2(type)
set ve=all
silent execute "normal! `[v`]dix\e"
set ve=
endfunction

nmap - :set opfunc=Foo1<cr>g@
nmap + :set opfunc=Foo2<cr>g@
----

On Mon, Mar 26, 2012 at 6:36 AM, Bram Moolenaar <Bram@moolenaar.net> wrote:
>
> Aaron Bohannon wrote:
>
>> Consider this line of text: "abc def".  If the cursor is on "d" and
>> you type "Dix<esc>" in normal mode, the result will depend on the
>> value of 'virtualedit'.
>>
>> * when ve="", you get "abcx "
>> * when ve="onemore", you get "abc x"
>> * when ve="all", you get "abc x"
>>
>> You will find that you get the same results if you define this
>> function and call it:
>>
>> function Foo()
>>   execute "normal! Dix\e"
>> endfunction
>>
>> Now consider these two variations:
>>
>> function Foo1()
>>   set ve=onemore
>>   execute "normal! Dix\e"
>> endfunction
>>
>> function Foo2()
>>   set ve=all
>>   execute "normal! Dix\e"
>> endfunction
>>
>> If you begin with ve="" and try calling these functions, you will be surprised:
>>
>> * with Foo1, you get "abc x"
>> * with Foo2, you get "abcx "
>>
>> This really threw me for a loop -- it took me forever to figure out
>> why my script wasn't working this morning.  Is this behavior
>> intentional or should I submit a bug?
>
> I cannot reproduce this, for me Foo2() has the same result as Foo1().
> I suggest you check where you cursor is when you call the function.
>
> --
> Vi is clearly superior to emacs, since "vi" has only two characters
> (and two keystrokes), while "emacs" has five.  (Randy C. Ford)
>
>  /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
> ///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
> \\\  an exciting new programming language -- http://www.Zimbu.org        ///
>  \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///

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