ZyX wrote:

> After launching
>     echo $':echom "Here"\nsshsshss:redir! >messages\n:messages\n:redir 
> END\n:qa!\n' | vim 
> -u NONE -c 'so test-expr-count.vim' -c 'normal a...' -c 'normal ssssss'
> I get the following output in messages file:
> 
>     Messages maintainer: Bram Moolenaar <[email protected]>
>     0
>     0
>     0
>     0
>     0
>     0
>     Here
>     1
>     3
>     1
>     2
>     1
>     1
> 
> while expected to have all 1's. Contents of `test-expr-count.vim':
>         function! DelNthSpace()
>             echom v:count1
>             return virtcol('.').'|'
>         endfunction
>         nnoremap <expr> s DelNthSpace()
> I get almost the same results for `v:count' and any bar movements, but
> not with other movements and expressions. Tested on vim-7.3 and
> vim-7.3.62-r840c3cadb842.

If I understand it correctly, your problem is that v:count and v:count1
are not reset when evaluating the expression of a mapping when there is
no count.

What happens is that the variables are only set when entering a count,
and after the command character has been entered.  I suppose we also
need to set them before getting the first character, when we don't know
yet whether it's a count or not.  That's when the expression will be
evaluated when there is no count.

Try out this patch:

*** ../vim-7.3.063/src/normal.c 2010-10-13 18:06:42.000000000 +0200
--- src/normal.c        2010-11-24 13:10:46.000000000 +0100
***************
*** 648,653 ****
--- 648,669 ----
      dont_scroll = FALSE;      /* allow scrolling here */
  #endif
  
+ #ifdef FEAT_EVAL
+     /* Set v:count here, when called from main() and not a stuffed
+      * command, so that v:count can be used in an expression mapping
+      * when there is no count. */
+     if (toplevel && stuff_empty())
+     {
+       long count = ca.count0;
+ 
+       /* multiply with ca.opcount the same way as below */
+       if (ca.opcount != 0)
+           count = ca.opcount * (count == 0 ? 1 : count);
+       set_vcount(count, count == 0 ? 1 : count, set_prevcount);
+       set_prevcount = FALSE;  /* only set v:prevcount once */
+     }
+ #endif
+ 
      /*
       * Get the command character from the user.
       */

-- 
ARTHUR: The swallow may fly south with the sun, or the house martin or the
        plover seek warmer hot lands in winter, yet these are not strangers to
        our land.
SOLDIER: Are you suggesting coconuts migrate?
                 "Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD

 /// Bram Moolenaar -- [email protected] -- 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_dev" 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

Raspunde prin e-mail lui