Loading ...
Sorry, an error occurred while loading the content.

Re: [BUG?] Modifications of visual selection are not remembered during mapping execution

Expand Messages
  • Bram Moolenaar
    ... This is a puzzle. Can you write this as a Vim script instead of a one-liner shell command? Can you map something else than e (is that taken literally or
    Message 1 of 6 , Jul 7, 2011
    • 0 Attachment
      ZyX wrote:

      > Consider the following script:
      >
      > vim -N -u NONE -c 'call setline(".", range(1000))' \
      > -c 'exe "fu! EV()\nechom 0\nnormal! gv30j\nendfu"' \
      > -c 'vnoremap <silent> \e :call EV()<CR>' \
      > -s <(<<< 'V4j\e')
      >
      > You will see that while function EV was called 5 times (five zeroes in
      > :messages), cursor is on the line containing number 33, while it is
      > expected to be on line with number 5*30=150.

      This is a puzzle. Can you write this as a Vim script instead of a
      one-liner shell command? Can you map something else than \e (is that
      taken literally or converted into an escape?). Why would the function
      be called five times, there is only one \e.

      --
      If VIM were a woman, I'd marry her. Slim, organized, helpful
      and beautiful; what's not to like? --David A. Rogers

      /// Bram Moolenaar -- Bram@... -- 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
    • ZyX
      Reply to message «Re: [BUG?] Modifications of visual selection are not remembered during mapping execution», sent 15:34:12 07 July 2011, Thursday ... It is
      Message 2 of 6 , Jul 7, 2011
      • 0 Attachment
        Reply to message «Re: [BUG?] Modifications of visual selection are not
        remembered during mapping execution»,
        sent 15:34:12 07 July 2011, Thursday
        by Bram Moolenaar:

        > This is a puzzle. Can you write this as a Vim script instead of a
        > one-liner shell command?
        It is already normal vimscript: equivalent to
        vim -N -u NONE -S <(<<EOF
        call setline(".", range(1000))
        function! EV()
        echom 0
        normal! gv30j
        endfunction
        vnoremap e :call EV()<CR>
        call feedkeys("V4je")
        EOF)

        > Can you map something else than \e (is that
        > taken literally or converted into an escape?).
        Taken literally. I can, it does not matter.

        > Why would the function
        > be called five times, there is only one \e.
        :h v_:
        :h :call | /doesn't handle

        Original message:
        > ZyX wrote:
        > > Consider the following script:
        > > vim -N -u NONE -c 'call setline(".", range(1000))' \
        > >
        > > -c 'exe "fu! EV()\nechom 0\nnormal! gv30j\nendfu"' \
        > > -c 'vnoremap <silent> \e :call EV()<CR>' \
        > > -s <(<<< 'V4j\e')
        > >
        > > You will see that while function EV was called 5 times (five zeroes in
        > >
        > > :messages), cursor is on the line containing number 33, while it is
        > >
        > > expected to be on line with number 5*30=150.
        >
        > This is a puzzle. Can you write this as a Vim script instead of a
        > one-liner shell command? Can you map something else than \e (is that
        > taken literally or converted into an escape?). Why would the function
        > be called five times, there is only one \e.
      • Bram Moolenaar
        ... Well, if you found that you can also find: When a range is given and the function doesn t handle it itself, the function is executed for each line in the
        Message 3 of 6 , Jul 7, 2011
        • 0 Attachment
          ZyX wrote:

          > > This is a puzzle. Can you write this as a Vim script instead of a
          > > one-liner shell command?
          > It is already normal vimscript: equivalent to
          > vim -N -u NONE -S <(<<EOF
          > call setline(".", range(1000))
          > function! EV()
          > echom 0
          > normal! gv30j
          > endfunction
          > vnoremap e :call EV()<CR>
          > call feedkeys("V4je")
          > EOF)
          >
          > > Can you map something else than \e (is that
          > > taken literally or converted into an escape?).
          > Taken literally. I can, it does not matter.
          >
          > > Why would the function
          > > be called five times, there is only one \e.
          > :h v_:
          > :h :call | /doesn't handle

          Well, if you found that you can also find:

          When a range is given and the function doesn't handle it
          itself, the function is executed for each line in the range,
          with the cursor in the first column of that line. The cursor
          is left at the last line (possibly moved by the last function
          call).

          And:

          If [range] is excluded, ":{range}call" will call the function for
          each line in the range, with the cursor on the start of each line.

          --
          hundred-and-one symptoms of being an internet addict:
          263. You have more e-mail addresses than shorts.

          /// Bram Moolenaar -- Bram@... -- 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
        • MacDonald, Stuart
          From: On Behalf Of ZyX ... This can be simplified to vim -N -u NONE -S
          Message 4 of 6 , Jul 7, 2011
          • 0 Attachment
            From: On Behalf Of ZyX
            > Subject: Re: [BUG?] Modifications of visual selection are not remembered
            > during mapping execution
            >
            > It is already normal vimscript: equivalent to
            > vim -N -u NONE -S <(<<EOF
            > call setline(".", range(1000))
            > function! EV()
            > echom 0
            > normal! gv30j
            > endfunction
            > vnoremap e :call EV()<CR>
            > call feedkeys("V4je")
            > EOF)

            This can be simplified to
            vim -N -u NONE -S <(<<EOF
            call setline(".", range(1000))
            call feedkeys("V4j:normal gv30j\<CR>")
            EOF)

            and still exhibit the behaviour. (The echom 0's are missing of course.)
            It doesn't look like a problem with mappings.

            The following exhibits the same behaviour
            vim -N -u NONE -S <(<<EOF
            call setline(".", range(1000))
            call feedkeys("V4j\<Esc>")
            call feedkeys(":1,5:normal gv30j\<CR>")
            EOF)

            > > > You will see that while function EV was called 5 times (five
            > > > zeroes in :messages), cursor is on the line containing number 33,
            > > > while it is expected to be on line with number 5*30=150.

            It looks like what you want is something like
            vim -N -u NONE
            :call setline(".", range(1000))
            V30jgv30jgv30jgv30jgv30j

            (sorry, couldn't figure out how to wedge a [count] in there) but that
            only works because when gv is typed there is no previous visual
            selection to swap with so it fails to do anything. Equivilantly
            vim -N -u NONE
            :call setline(".", range(1000))
            V30j30j30j30j30j

            Perhaps you wanted a [count] instead of a [range]?

            ...Stu

            --
            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
          • ZyX
            Reply to message «RE: [BUG?] Modifications of visual selection are not remembered during mapping execution», sent 21:37:58 07 July 2011, Thursday by
            Message 5 of 6 , Jul 7, 2011
            • 0 Attachment
              Reply to message «RE: [BUG?] Modifications of visual selection are not
              remembered during mapping execution»,
              sent 21:37:58 07 July 2011, Thursday
              by MacDonald, Stuart:

              I did not want anything here: while testing an answer to one question on
              stackoverflow I noticed strange behavior and went to vim-dev to ask whether it
              is a bug (that is why I wrote [BUG?], not [BUG]). Thanks to Bram, he explained
              what is going on here.

              I personally will never write such mapping: using :normal to reenter visual mode
              after you escaped from it using the colon looks like some black magic to me; I
              normally use <expr> mappings or feedkeys() here.

              Original message:
              > From: On Behalf Of ZyX
              >
              > > Subject: Re: [BUG?] Modifications of visual selection are not remembered
              > > during mapping execution
              > >
              > > It is already normal vimscript: equivalent to
              > >
              > > vim -N -u NONE -S <(<<EOF
              > > call setline(".", range(1000))
              > > function! EV()
              > >
              > > echom 0
              > > normal! gv30j
              > >
              > > endfunction
              > > vnoremap e :call EV()<CR>
              > > call feedkeys("V4je")
              > > EOF)
              >
              > This can be simplified to
              > vim -N -u NONE -S <(<<EOF
              > call setline(".", range(1000))
              > call feedkeys("V4j:normal gv30j\<CR>")
              > EOF)
              >
              > and still exhibit the behaviour. (The echom 0's are missing of course.)
              > It doesn't look like a problem with mappings.
              >
              > The following exhibits the same behaviour
              > vim -N -u NONE -S <(<<EOF
              > call setline(".", range(1000))
              > call feedkeys("V4j\<Esc>")
              > call feedkeys(":1,5:normal gv30j\<CR>")
              > EOF)
              >
              > > > > You will see that while function EV was called 5 times (five
              > > > > zeroes in :messages), cursor is on the line containing number 33,
              > > > > while it is expected to be on line with number 5*30=150.
              >
              > It looks like what you want is something like
              > vim -N -u NONE
              >
              > :call setline(".", range(1000))
              >
              > V30jgv30jgv30jgv30jgv30j
              >
              > (sorry, couldn't figure out how to wedge a [count] in there) but that
              > only works because when gv is typed there is no previous visual
              > selection to swap with so it fails to do anything. Equivilantly
              > vim -N -u NONE
              >
              > :call setline(".", range(1000))
              >
              > V30j30j30j30j30j
              >
              > Perhaps you wanted a [count] instead of a [range]?
              >
              > ...Stu
            Your message has been successfully submitted and would be delivered to recipients shortly.