created September 19, 2006 · complexity basic · author mz · version n/a
The default is that when you close a tab, the tab to the right of the tab you just closed becomes the current tab. This mapping closes the current tab and makes the tab to the left of the tab you just closed the current tab. I like this to provide symmetry with tabopen (new tabs go to the right of the tab you were just on). This way, if I'm editing a file, and do something quickly in a new tab, then close that tab, I get back to my original tab. Obviously the keys for the mapping can be changed to whatever you want.
noremap <silent><C-S-w> :if tabpagenr() != tabpagenr('$')<CR>:tabclose<CR>:if tabpagenr() > 1<CR>:tabprev<CR>:endif<CR>:else<CR>:tabclose<CR>:endif<CR>
I hacked up the following, which performs the above if about to close a tab, otherwise just does :q.
function! CloseSomething() if winnr("$") == 1 && tabpagenr("$") > 1 && tabpagenr() > 1 && tabpagenr() < tabpagenr("$") tabclose | tabprev else q endif endfunction map <C-x> :call CloseSomething()<CR>
184.108.40.206 21:29, 19 December 2008 (UTC)