Vim, reopen last closed window, that was in split

后端 未结 5 1577
清酒与你
清酒与你 2020-12-25 09:58

Is it possible to reopen closed window in vim, that was in split?

Something like ctrl+shift+t with browser tabs?

相关标签:
5条回答
  • 2020-12-25 10:20

    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.
    
    0 讨论(0)
  • 2020-12-25 10:25

    :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.

    0 讨论(0)
  • 2020-12-25 10:32

    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.

    0 讨论(0)
  • 2020-12-25 10:35

    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.

    0 讨论(0)
  • 2020-12-25 10:38

    Nice question! I was thinking to something like the following:

    nmap <c-s-t> :vs<bar>:b#<CR>
    

    It should work as you want.

    0 讨论(0)
提交回复
热议问题