Check if current tab is empty in vim

前端 未结 3 1251
南方客
南方客 2021-01-12 20:05

I am writing a vim plugin in which I need to check if the current tab the user is looking at is empty. If it is not empty, like say the user is already viewing a buffer or h

3条回答
  •  栀梦
    栀梦 (楼主)
    2021-01-12 20:45

    Let's assume that there are multiple windows in the tab, but all the windows' buffers are empty.

    Maybe you'd like to say that this tab is NOT empty. If that's the case, we don't need to go through all the tabs. The following will work.

    function! TabIsEmpty()
        return winnr('$') == 1 && len(expand('%')) == 0 && line2byte(line('$') + 1) <= 2
    endfunction
    

提交回复
热议问题