Search code examples
vimtabs

Switch to last-active tab in VIM


In Vim, is there a way to quickly toggle between the current tab and the last-active tab? Sort of the way '' toggles between the current line and the last-active line. Plugins / keyboard mappings / voodoo all acceptable.


Solution

  • Put this in your .vimrc:

    if !exists('g:lasttab')
      let g:lasttab = 1
    endif
    nmap <Leader>tl :exe "tabn ".g:lasttab<CR>
    au TabLeave * let g:lasttab = tabpagenr()
    

    Then, in normal mode, type \tl to swap to the tab you viewed last.