user1816631
user1816631

Reputation:

Ask vim how many splits are in current tab

I am trying to make a make a binding, <Leader>t, to toggle a specific split in and out of its own tab. The two commands are

" Open current split in a new tab
map <Leader>T <C-w>T
" Close current buffer (and thus the new tab)
map <Leader>t <C-w>c

How do I combine them? Something like

map <Leader>t numberOfSplitsInCurrentTab > 1 ? <C-w>T : <C-w>c

Upvotes: 0

Views: 133

Answers (1)

user1816631
user1816631

Reputation:

Answering my own question for others to learn from.

function! ToggleSingleSplit()
    if len(tabpagebuflist()) > 1
        :tabedit %
    else
        :close
    endif
endfunction

map <Leader>t :call ToggleSingleSplit()<CR>

There is probably a more concise way to do this, but reads well and is easy to edit for people like myself who is less versed in vimscript.

And for the curious, here are the resources I used:

Upvotes: 2

Related Questions