Wikia

Vim Tips Wiki

Have focus on left tab after tabclose

Talk0
1,610pages on
this wiki
Revision as of 06:21, July 13, 2012 by JohnBot (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Tip 1333 Printable Monobook Previous Next

created 2006 · complexity basic · author mz · version n/a


By default when a tab is closed, if another tab is open to the right of the tab that was just closed, it will become the "in focus" or current tab. However, when editing quickly this does not provide symmetry with the :tabopen command, because the :tabopen command opens a new tab to the right, and the :tabclose does restore focus to the original tab upon closing. With the following command in the .vimrc file, when editing a file, if the user needs to do something quickly in a new tab, they can use a mapping to close it and return to the original tab.

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>

CommentsEdit

The following accomplishes the same as above, but if a tab is not being closed, will just call the :q command.

function! CloseSomething()
  if winnr("$") == 1 && tabpagenr("$") > 1 && tabpagenr() > 1 && tabpagenr() < tabpagenr("$")
    tabclose | tabprev
  else
    q
  endif
endfunction
map <C-x> :call CloseSomething()<CR>
Advertisement | Your ad here

Around Wikia's network

Random Wiki