Vim: close all tabs to the right

Solution 1:

No native commands for this exist, but you can create your own fairly easily using Vim script. Here is a basic example that lets you close the tabs to the right of the current tab, and the tabs to the left:

function! TabCloseRight(bang)
    let cur=tabpagenr()
    while cur < tabpagenr('$')
        exe 'tabclose' . a:bang . ' ' . (cur + 1)
    endwhile
endfunction

function! TabCloseLeft(bang)
    while tabpagenr() > 1
        exe 'tabclose' . a:bang . ' 1'
    endwhile
endfunction

command! -bang Tabcloseright call TabCloseRight('<bang>')
command! -bang Tabcloseleft call TabCloseLeft('<bang>')

Solution 2:

Slightly improved version of davidxk's answer that works with multiple splits per tab:

:.+1,$tabdo :tabc