FANDOM


(fix name)
(Cleaned up wording and checked functionality.)
Line 1: Line 1:
{{review}}
 
 
{{TipImported
 
{{TipImported
 
|id=1333
 
|id=1333
Line 12: Line 11:
 
|category2=
 
|category2=
 
}}
 
}}
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 <tt>tabopen</tt> (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.
+
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 semetry with the <tt>:tabopen</tt> command because the <tt>:tabopen</tt> command opens a new tab to the right, and the <tt>:tabclose</tt> does not put the user back to that 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, then close that tab, they will be placed back into their original tab.
   
 
<pre>
 
<pre>
Line 19: Line 18:
   
 
==Comments==
 
==Comments==
I hacked up the following, which performs the above if about to close a tab, otherwise just does :q.
+
The following accomplishes the same as above, but if a tab is not being closed, will just call the <tt>:q</tt> command.
   
 
<pre>
 
<pre>
Line 31: Line 30:
 
map <C-x> :call CloseSomething()<CR>
 
map <C-x> :call CloseSomething()<CR>
 
</pre>
 
</pre>
[[Special:Contributions/216.239.45.4|twifkak]] 21:29, 19 December 2008 (UTC)
 

Revision as of 20:04, January 10, 2011

Tip 1333 Printable Monobook Previous Next

created September 19, 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 semetry with the :tabopen command because the :tabopen command opens a new tab to the right, and the :tabclose does not put the user back to that 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, then close that tab, they will be placed back into their 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>

Comments

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>
Community content is available under CC-BY-SA unless otherwise noted.