[ACCEPTED]-Undo Close Tab in Vim-tabs

Accepted answer
Score: 151

Your file is probably still open in a buffer:

:ls " get the buffer number
:tabnew +Nbuf " where N is the buffer number

To 1 reopen buffer 18, for example:

:tabnew +18buf
Score: 37

Reopens recently closed file in new tab

Edit: Please 3 use greyfade's answer. I don't like my answer, but 2 I'm keeping it here for references and useful 1 comment info.

Score: 12

I'm using an MRU (most recently used files) plugin. So I can edit the last 30 7 files I've just edited

Here are the MRU plugin 6 metadata:

File: mru.vim
Author: Yegappan Lakshmanan (yegappan AT yahoo DOT com)
Version: 3.2   Last Modified:
September 22, 2008


To list and edit files from 5 the MRU list, you can use the ":MRU" command. The 4 ":MRU" command displays the MRU 3 file list in a temporary Vim window. If the 2 MRU window is already opened, then the MRU 1 list displayed in the window is refreshed.

Score: 6

Simple answer is no, there is nothing built-in.

But 5 a workable solution would be to use a plug-in 4 like the excellent BufExplorer. Since it defaults 3 to listing the most recently used buffers 2 first, reopening a closed tab would be as 1 simple as pressing \bet

Score: 1

Use the plug-in Ben Suggested: BufExplorer Github Mirror

In his answer 2 one would have to press <Leader>be<Down>t. Adding a bit shortcut:

map <silent><leader>t <leader>be<Down>t

So 1 that simply <leader>t would do the work.

Score: 1

If there were a BufferClose event this would be easy... but it seems that it is not possible since it is not possible for window creation.

But 5 in the case of tabs we can detect if a tab 4 was closed by keeping a tab count and counting 3 the difference between TabLeave and TabEnter.

Usage: <leader>tr reopens 2 the last closed tab on a new tab (supposing 1 the tab had only a single buffer):

let g:reopenbuf = expand('%:p')
function! ReopenLastTabLeave()
  let g:lastbuf = expand('%:p')
  let g:lasttabcount = tabpagenr('$')
function! ReopenLastTabEnter()
  if tabpagenr('$') < g:lasttabcount
    let g:reopenbuf = g:lastbuf
function! ReopenLastTab()
  execute 'buffer' . g:reopenbuf
augroup ReopenLastTab
  autocmd TabLeave * call ReopenLastTabLeave()
  autocmd TabEnter * call ReopenLastTabEnter()
augroup END
" Tab Restore
nnoremap <leader>tr :call ReopenLastTab()<CR>

More Related questions