On Di, 25 Mär 2014, Ben Fritz wrote:

> On Wednesday, March 19, 2014 2:43:46 PM UTC-5, Christian Brabandt wrote:
> > > The problem is, that executing "startinsert" while in replace mode
> > 
> > > doesn't seem to do anything. "startreplace" when in insert mode
> > 
> > > likewise has no effect, and the same for "startgreplace".
> > 
> > > 
> > 
> > > Using "stopinsert | startinsert" doesn't work either; the editor just
> > 
> > > seems to ignore the startinsert altogether if I do that, leaving it in
> > 
> > > normal mode always.
> > 
> > 
> > 
> > This seems to work here (7.4.155, terminal and gtk gvim).
> > 
> > 
> 
> What part works?
> 
> Here is a Vim I just tested in Windows 7 64-bit:
> 
> VIM - Vi IMproved 7.4 (2013 Aug 10, compiled Mar 24 2014 08:11:09)
> MS-Windows 32-bit GUI version with OLE support
> Included patches: 1-213
> Compiled by [email protected]:http://SteveHallArchitecture.com
> Huge version with GUI.  Features included (+) or not (-):
> 
> In this version, I source my original script (repeated at the end of this 
> message), then create 4 total tabs. In the first tab, I leave Vim in insert 
> mode. I go to the second tab, enter insert mode, then click on tab 3 to 
> switch to it without leaving insert mode. On tab 3, I press R to enter 
> replace mode. I click to enter tab 4 again without leaving the mode. On tab 4 
> I enter vreplace mode by pressing gR. If I then click on tab 1 Vim is in 
> normal mode again (good). If I click on tab 2 Vim is in insert mode (good). 
> If I click back on tab 1 then on tab 3 Vim is in replace mode (good). If I 
> click back on tab 1 then on tab 4 Vim is in vreplace mode (good). But now 
> that I am on tab 4, if I click on tab 2 or tab 3 without clicking tab 1 
> first, Vim stays in vreplace mode. The same thing happens for the insert and 
> replace mode tabs. Vim does not switch between the various insert modes, 
> although switching between insert modes and normal mode works just fine.
> 
> Here is the script I sourced, again:
> 
>     augroup TAB_MODES 
>       au! 
>       autocmd TabLeave * let t:lastmode = mode(1) 
>       autocmd TabEnter * if !exists('t:lastmode') | let t:lastmode = 'n' | 
> endif 
>       autocmd TabEnter * if t:lastmode ==# 'n'  | stopinsert    | endif 
>       autocmd TabEnter * if t:lastmode ==# 'i'  | startinsert   | endif 
>       autocmd TabEnter * if t:lastmode ==# 'R'  | startreplace  | endif 
>       autocmd TabEnter * if t:lastmode ==# 'Rv' | startgreplace | endif 
>     augroup END
> 

Thanks. That helped to reproduce the issue. Initially I simply tried 
from insert mode with <c-o>:startreplace which worked.

The problem is, the startinsert command checks, if it is in one of the 
insert modes and since replace and vreplace mode are all some kind of 
insert mode, it returns early. The following patch fixes that problem, 
by also considering the used ex commadn.

diff --git a/src/ex_docmd.c b/src/ex_docmd.c
--- a/src/ex_docmd.c
+++ b/src/ex_docmd.c
@@ -9546,7 +9546,9 @@ ex_startinsert(eap)
 
     /* Ignore the command when already in Insert mode.  Inserting an
      * expression register that invokes a function can do this. */
-    if (State & INSERT)
+    if ((State == INSERT && eap->cmdidx == CMD_startinsert)
+           || (State == REPLACE && eap->cmdidx == CMD_startreplace)
+           || (State == VREPLACE && eap->cmdidx == CMD_startgreplace))
        return;
 
     if (eap->cmdidx == CMD_startinsert)

By itself this doesn't fix the your problem, since Vim will remain in 
the insert mode it was in the previous mode. This is, because in the 
edit() function there is no code to check, that restart_edit changed. So 
you still need to explicitly stop insert mode before starting another 
edit mode.

That also explains, why it worked for you, when you changed tabs to the 
one where you left Vim in normal mode.

You script therefore needs to be adjusted to

augroup TAB_MODES
    au!
    autocmd TabLeave * let t:lastmode = mode(1)
    autocmd TabEnter * if !exists('t:lastmode') | let t:lastmode = 'n' | endif
    autocmd Tabenter * stopinsert
    autocmd TabEnter * if t:lastmode ==# 'i'  | startinsert   | endif
    autocmd TabEnter * if t:lastmode ==# 'R'  | startreplace  | endif
    autocmd TabEnter * if t:lastmode ==# 'Rv' | startgreplace | endif
augroup END

Best,
Christian
-- 
Es bleibt zwischen Menschen, sie seinen noch so eng verbunden, immer
ein Abgrund offen, den nur die Liebe, und auch nur mit einem Notsteg,
überbrücken kann.
                -- Hermann Hesse

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

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Raspunde prin e-mail lui