Vim Tips Wiki
m (→‎Comments: sign comment)
(assign tip ID)
Line 1: Line 1:
  +
{{TipNew
{{TipProposed
 
|id=0
+
|id=1648
|previous=0
+
|previous=1647
|next=0
+
|next=1649
 
|created=June 30, 2008
 
|created=June 30, 2008
 
|complexity=basic
 
|complexity=basic
Line 36: Line 36:
   
 
==Comments==
 
==Comments==
  +
{{todo}}
This page was created in June 2008 and somehow missed being flagged as a "tip" so I am adding it for processing with the February 2010 new tips. [[User:JohnBeckett|JohnBeckett]] 07:15, January 25, 2011 (UTC)
 
----
 
 
Should probably add logic of some sort for other modes (command-line, replace, visual, etc.). Currently only properly handles insert and normal modes. –[[User:Fritzophrenic|Fritzophrenic]] 03:59, February 14, 2011 (UTC)
 
Should probably add logic of some sort for other modes (command-line, replace, visual, etc.). Currently only properly handles insert and normal modes. –[[User:Fritzophrenic|Fritzophrenic]] 03:59, February 14, 2011 (UTC)

Revision as of 04:10, 23 March 2011

Tip 1648 Printable Monobook Previous Next

created June 30, 2008 · complexity basic · author Sightless · version 7.0


Usually when switching tabpages, Vim stays in the same mode. Some people prefer it if Vim returns to the same mode it was in when the tab page being entered was last used. This behavior reinforces the idea of tab pages as separate workspaces.

The following autocommands store the current mode when leaving a tab into a tab-local variable. On entry into the tab, the mode is restored. Place these autocmds in your vimrc or a .vim file in ~/.vim/plugin/ (or $HOME/vimfiles/plugin on Windows).

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

Comments

 TO DO 
Should probably add logic of some sort for other modes (command-line, replace, visual, etc.). Currently only properly handles insert and normal modes. –Fritzophrenic 03:59, February 14, 2011 (UTC)