r/vim•
inside_

Undo close tab?

Hi,

Have you heard of such a plugin?

I accidentaly closed my current tab with my superbe window splits layout and then was sad I couldn't "ressurect" it. An undo close tab would have saved me some time creating the same window split layout.

Best,

Posted Sep 10, 2015, 1:13 PM UTC

1711
amphetamachine•

Have you tried using sessions?

3
dddbbbFastFold made vim fast again•

And there are some plugins to automate session capturing like https://github.com/tpope/vim-obsession

So you could load the session after closing the tab and (if the open tab was saved in the session), you should have your splits back.

2
inside_OP•

I thought about diffing the session, but WTS-Poker-II's solution does the job.

vim-obsession is great and so simple, I just started using it, thanks!

2
WTS-Poker-II•

This seems to work pretty well:

" requires https://github.com/godlygeek/windowlayout

function! s:UndoCloseTab()
    if exists('s:layout') && !empty(s:layout)
        tabnew
        call windowlayout#SetLayout(s:layout)
        unlet s:layout
    endif
endfunction
command! UndoCloseTab call s:UndoCloseTab()

function! s:CloseTab()
    if tabpagenr('$') != 1
        let s:layout = windowlayout#GetLayout()
        tabclose
    endif
endfunction
command! CloseTab call s:CloseTab()

nnoremap <Leader>c :<C-u>CloseTab<CR>
nnoremap <Leader>u :<C-u>UndoCloseTab<CR>
3
inside_OP•

This is really good, thank you!

2
WTS-Poker-II•

You're welcome. Here's an improved version that maintains a 'close tab history' instead of only remembering the last closed tab:

" requires https://github.com/godlygeek/windowlayout

let s:close_tab_history = []

function! s:UndoCloseTab()
    if len(s:close_tab_history)
        tabnew
        call windowlayout#SetLayout(remove(s:close_tab_history, -1))
    endif
endfunction
command! UndoCloseTab call s:UndoCloseTab()

function! s:CloseTab()
    if tabpagenr('$') != 1
        call add(s:close_tab_history, windowlayout#GetLayout())
        tabclose
    endif
endfunction
command! CloseTab call s:CloseTab()

nnoremap <Leader>c :<C-u>CloseTab<CR>
nnoremap <Leader>u :<C-u>UndoCloseTab<CR>
2
inside_OP•

Bravo, it's exactly what I was looking for!!

2
AndrewRadev•

I've got a plugin for that: https://github.com/AndrewRadev/undoquit.vim. It works for splits as well.

3
inside_OP•

Awesome plugin, very useful. Thanks!!

1
goriloncho•

Try this:

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

Source: http://stackoverflow.com/a/573681/1126380

1
inside_OP•

This opens a tab with the specified buffer. It won't bring back all window split...

1