Cancel split window in Vim

前端 未结 10 1146
小鲜肉
小鲜肉 2021-01-29 18:07

I have split my windows horizontally. Now how can I return to normal mode, i.e. no split window just one window without cancelling all of my open windows. I have 5 and do not wa

10条回答
  •  伪装坚强ぢ
    2021-01-29 18:35

    I understand you intention well, I use buffers exclusively too, and occasionally do split if needed.

    below is excerpt of my .vimrc

    " disable macro, since not used in 90+% use cases
    map q 
    " q,  close/hide current window, or quit vim if no other window
    nnoremap q :if winnr('$') > 1 \|hide\|else\|silent! exec 'q'\|endif
    " qo, close all other window    -- 'o' stands for 'only'
    nnoremap qo :only
    set hidden
    set timeout
    set timeoutlen=200   " let vim wait less for your typing!
    

    Which fits my workflow quite well

    If q was pressed

    • hide current window if multiple window open, else try to quit vim.

    if qo was pressed,

    • close all other window, no effect if only one window.

    Of course, you can wrap that messy part into a function, eg

    func! Hide_cur_window_or_quit_vim()
        if winnr('$') > 1
            hide
        else
            silent! exec 'q'
        endif
    endfunc
    nnoremap q :call Hide_cur_window_or_quit_vim()
    

    Sidenote: I remap q, since I do not use macro for editing, instead use :s, :g, :v, and external text processing command if needed, eg, :'{,'}!awk 'some_programm', or use :norm! normal-command-here.

提交回复
热议问题