On Thu, 27 Apr 2006, Bram Moolenaar wrote:
Gerald Lai wrote:
Nah. Good riddance :) It will actually fix a bug in one of my scripts.
Bram, could you make Vim do
-- (insert) VISUAL --
instead when it now does
-- INSERT VISUAL --
With the weird mode prevented, this should never appear now. Perhaps I
should offer a reward if you are still able to get it somehow!
So what happens when
i<C-r>=Test()<CR>
is done for
fun! Test()
normal! v
return ""
endf
?
Does it go into -- (insert) VISUAL -- mode? It should.
No, this is not a legal way to change mode. The CTRL-R = command is
there to get text to be inserted, not to change mode. You can use
CTRL-O v for that.
Yes, this may not be a legal way to change modes, but I believe (but have
not confirmed) many existing scripts rely on <C-r>= to evaluate
functions that do change modes in some way. If this is true, this is one
bug that is relied on heavily by many.
As seen in ":help i_ctrl-r", '=' is used to enter an expression that
returns a string. While evaluating for that returned string, a function
could perform many tasks of switching to other modes.
Consider the following:
(1) imap <F2> <C-o>:call InsFunc()<CR>
(2) imap <F3> <C-r>=InsFunc()<CR>
fun InsFunc()
let a = mode()
let b = col(".")
"execute command
exe "norm! \<Del>"
return "\<Esc>v"
endf
In the past, those keen enough would notice that Vim has had trouble
dealing with functions that act in Insert mode:
(a) mode() would only return "i" or "R" for case (2)
(b) current Insert cursor column position is incorrect for case (1)
but correct for case (2)
(c) the execute command would delete arbitrarily before/after Insert
cursor position, depending on whether the Insert cursor is at the
end-of-line (virtualedit=""); case (2) always deletes after the
cursor position
(The person who would probably be most familiar with these Insert mode
problems is Steve Hall, who maintains Cream.)
In all cases (a), (b), and (c), case (2) is the natural choice for
performing Insert mode functions. It just works ;)
On the return, case (2) should switch modes to -- VISUAL -- mode. I'm
unsure how many Vim scripts use this technique, but I'm not willing to
dispute that <C-r>= was one of Vim 6's ways to do Vim 7's feedkeys().
Does anybody else have an opinion on this? :)
--
Gerald