Vim, reopen last closed window, that was in split
VimSplitVim Problem Overview
Is it possible to reopen closed window in vim, that was in split?
Something like ctrl+shift+t with browser tabs?
Vim Solutions
Solution 1 - Vim
:vs#
will split current window vertically and open the alternate file.
It's so simple that you don't need to bind it to key.
Solution 2 - Vim
Nice question! I was thinking to something like the following:
nmap <c-s-t> :vs<bar>:b#<CR>
It should work as you want.
Solution 3 - Vim
No need for SHIFT:
nmap <c-t> :vs<bar>:b#<CR>
In conjunction with CTRL the characters are handled equally by vim, capitalized or not.
Actually also in the answer before, CTRLn and CTRLSHIFTN should both work.
Solution 4 - Vim
I've gotten this to work by using bufmru.vim
!
The following command, :ReopenLastTab
, will re-split the last-open buffer:
command ReopenLastTab execute "vsplit" bufname(g:bufmru_bnrs[1])
I installed bufmru using Vundle
, as below, but of course you can install it any way you like.
#.vimrc
" Install bufmru with Vundle
Plugin 'vim-scripts/bufmru.vim'
let g:bufmru_switchkey = "<c-t>" " I never use this: the default is Space, but I don't need to use it so set it to something I don't care about.
Solution 5 - Vim
If anyone need something more generic I made this function.
Just place it in your .vimrc
" open last closed buffer
function! OpenLastClosed()
let last_buf = bufname('#')
if empty(last_buf)
echo "No recently closed buffer found"
return
endif
let result = input("Open ". last_buf . " in (n)ormal (v)split, (t)ab or (s)plit ? (n/v/t/s) : ")
if empty(result) || (result !=# 'v' && result !=# 't' && result !=# 's' && result !=# 'n')
return
endif
if result ==# 't'
execute 'tabnew'
elseif result ==# 'v'
execute "vsplit"
elseif result ==# 's'
execute "split"
endif
execute 'b ' . last_buf
endfunction
nnoremap <C-t> :call OpenLastClosed() <CR>
Call it with Ctrl+t
and then select where you want to open that file.