How can I automatically close preview window after I move cursor to another window in Vim?

前端 未结 1 1003
别那么骄傲
别那么骄傲 2021-01-16 15:57

I would like the preview window disappears automatically when cursor is not in the preview window or preview window loses the focus. Is it possible?

1条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-16 16:31

    You may want to have a look on autocommands. A simple example would be:

    autocmd WinLeave * pc
    

    Which calls pc (close preview window) every time you leave a window. A more involved example could use a separate function that performs extra checking:

    autocmd WinLeave * call ClosePreviewWindow()
    
    function ClosePreviewWindow()
        if &pvw
            pclose
        endif
    endfunction
    

    Check :h autocmd.txt to learn more. This file has a complete listing of autocommand events in section 5, so you can choose the one that fits better.

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