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

Re: Insert mode problem with multiple tabs

Expand Messages
  • björn
    ... Ben, thanks for the script. Unfortunately it doesn t work at all for me. With that script it seems to be more or less random chance whether a tab is in
    Message 1 of 11 , Jul 1, 2008
    • 0 Attachment
      2008/6/30 Ben Schmidt <mail_ben_schmidt@...>:
      >
      > Ben Schmidt wrote:
      >>> Thanks for this and other suggestions, but I was not asking for how to
      >>> exit insert mode when switching tabs. The desired behaviour is that
      >>> each tab remembers which mode it is in when you exit the tab and
      >>> restores that mode when you enter it again. I guess that it is not
      >>> possible with Vim script?
      >>
      >> I don't see why you couldn't do it simply, i.e. restricting to Insert and Normal
      >> modes. Doing it with Visual mode and Command Line mode is probably possible, too,
      >> but would be a lot more work, though I could see in some situations it could be
      >> useful. I don't know how possible it is to switch tabs while in those modes anyway.
      >>
      >> At any rate, this seems to work for me:
      >>
      >> augroup tabInsertMode
      >> au!
      >> au TabLeave * let t:tabInsertMode_lastmode = mode()
      >> \ | let t:tabInsertMode_lastcol = col('.')
      >> \ | if t:tabInsertMode_lastcol == col('$')
      >> \ | let t:tabInsertMode_lastmode = 'A'
      >> \ | endif
      >> au TabEnter * if exists('t:tabInsertMode_lastmode')
      >> \ | if t:tabInsertMode_lastmode == 'A'
      >> \ | if mode() == 'i' | call feedkeys("\<C-O>l")
      >> \ | else | call feedkeys("A") | endif
      >> \ | elseif t:tabInsertMode_lastmode == 'i'
      >> \ | if mode() != 'i' | call feedkeys("i") | endif
      >> \ | else
      >> \ | if mode() == 'i' | call feedkeys("\<Esc>") | endif
      >> \ | endif
      >> \ | endif
      >> augroup END
      >>
      >> I've made it into a Vim tip so others can use it/alter it/and there can be an
      >> 'official latest version' or such.
      >
      > Forgot to paste the link in. It's here:
      >
      > http://vim.wikia.com/wiki/Restore_the_last_used_mode_when_switching_tabpages

      Ben, thanks for the script. Unfortunately it doesn't work at all for
      me. With that script it seems to be more or less random chance
      whether a tab is in insert or normal mode when it is entered.
      Usually, if one tab is in insert mode all other tabs will also be in
      insert mode, but sometimes they switch back to normal mode by
      themselves.

      Not only that, sometimes when I switch tabs text will get inserted
      into the tab i switch to.

      I tried moving .vimrc/.gvimrc/.vim and created a .gvimrc containing
      only your script. Same result.

      Did anybody else get this to work?

      Björn

      --~--~---------~--~----~------------~-------~--~----~
      You received this message from the "vim_mac" maillist.
      For more information, visit http://www.vim.org/maillist.php
      -~----------~----~----~----~------~----~------~--~---
    • Timothy Grant
      ... Bjorn, I just tested and it looks like all the tabs start in insert mode, and the behaviour on switching is somewhat undefined. I have not seen the issue
      Message 2 of 11 , Jul 1, 2008
      • 0 Attachment
        On Tue, Jul 1, 2008 at 12:03 PM, björn <bjorn.winckler@...> wrote:

        2008/6/30 Ben Schmidt <mail_ben_schmidt@...>:
        >
        > Ben Schmidt wrote:
        >>> Thanks for this and other suggestions, but I was not asking for how to
        >>> exit insert mode when switching tabs.  The desired behaviour is that
        >>> each tab remembers which mode it is in when you exit the tab and
        >>> restores that mode when you enter it again.  I guess that it is not
        >>> possible with Vim script?
        >>
        >> I don't see why you couldn't do it simply, i.e. restricting to Insert and Normal
        >> modes. Doing it with Visual mode and Command Line mode is probably possible, too,
        >> but would be a lot more work, though I could see in some situations it could be
        >> useful. I don't know how possible it is to switch tabs while in those modes anyway.
        >>
        >> At any rate, this seems to work for me:
        >>
        >> augroup tabInsertMode
        >> au!
        >> au TabLeave * let t:tabInsertMode_lastmode = mode()
        >>            \ | let t:tabInsertMode_lastcol = col('.')
        >>            \ | if t:tabInsertMode_lastcol == col('$')
        >>            \ | let t:tabInsertMode_lastmode = 'A'
        >>            \ | endif
        >> au TabEnter * if exists('t:tabInsertMode_lastmode')
        >>            \ | if t:tabInsertMode_lastmode == 'A'
        >>            \ |   if mode() == 'i' | call feedkeys("\<C-O>l")
        >>            \ |   else | call feedkeys("A") | endif
        >>            \ | elseif t:tabInsertMode_lastmode == 'i'
        >>            \ |   if mode() != 'i' | call feedkeys("i") | endif
        >>            \ | else
        >>            \ |   if mode() == 'i' | call feedkeys("\<Esc>") | endif
        >>            \ | endif
        >>            \ | endif
        >> augroup END
        >>
        >> I've made it into a Vim tip so others can use it/alter it/and there can be an
        >> 'official latest version' or such.
        >
        > Forgot to paste the link in. It's here:
        >
        > http://vim.wikia.com/wiki/Restore_the_last_used_mode_when_switching_tabpages

        Ben, thanks for the script.  Unfortunately it doesn't work at all for
        me.  With that script it seems to be more or less random chance
        whether a tab is in insert or normal mode when it is entered.
        Usually, if one tab is in insert mode all other tabs will also be in
        insert mode, but sometimes they switch back to normal mode by
        themselves.

        Not only that, sometimes when I switch tabs text will get inserted
        into the tab i switch to.

        I tried moving .vimrc/.gvimrc/.vim and created a .gvimrc containing
        only your script.  Same result.

        Did anybody else get this to work?

        Björn

        Bjorn,

        I just tested and it looks like all the tabs start in insert mode, and the behaviour on switching is somewhat undefined. I have not seen the issue of text being inserted though.

        --
        Stand Fast,
        tjg.
        --~--~---------~--~----~------------~-------~--~----~
        You received this message from the "vim_mac" maillist.
        For more information, visit http://www.vim.org/maillist.php
        -~----------~----~----~----~------~----~------~--~---

      Your message has been successfully submitted and would be delivered to recipients shortly.