Wikia

Vim Tips Wiki

Changes: Tabclose instead of quit-all

Edit

Back to page

(adjust previous/next navigation + minor manual clean)
(Change <tt> to <code>, perhaps also minor tweak.)
 
Line 11: Line 11:
 
|category2=Tabs
 
|category2=Tabs
 
}}
 
}}
Occasionally users will improperly use the commands <tt>:qa</tt> or <tt>:qa!</tt> instead of the proper <tt>:tabclose</tt> to close a tab in a session, quitting the entire session instead. A few methods can be used to remap the <tt>:tabclose</tt> command to a more memoriable command as outlined below.
+
Occasionally users will improperly use the commands <code>:qa</code> or <code>:qa!</code> instead of the proper <code>:tabclose</code> to close a tab in a session, quitting the entire session instead. A few methods can be used to remap the <code>:tabclose</code> command to a more memoriable command as outlined below.
   
 
==Remap :tabclose to QA==
 
==Remap :tabclose to QA==
This method requires the plugin {{script|id=746|text=cmdalias.vim plugin}}. This plugin will allow you to keep your abbreviations in the context of a : command. Once this plugin is loaded add the following to your vimrc to create a user command for <tt>QA</tt>.
+
This method requires the plugin {{script|id=746|text=cmdalias.vim plugin}}. This plugin will allow you to keep your abbreviations in the context of a : command. Once this plugin is loaded add the following to your vimrc to create a user command for <code>QA</code>.
 
<pre>
 
<pre>
 
command! -bang QA :call TabQAll('<bang>')
 
command! -bang QA :call TabQAll('<bang>')
Line 30: Line 30:
 
</pre>
 
</pre>
   
Finally create an abbreviation for <tt>:qa</tt> to mean <tt>:QA</tt> which will allow you to not have to remember <tt>:QA</tt> making it easier to use the command you are already familiar with to "close" your tab. To accomplish this add the following to your vimrc:
+
Finally create an abbreviation for <code>:qa</code> to mean <code>:QA</code> which will allow you to not have to remember <code>:QA</code> making it easier to use the command you are already familiar with to "close" your tab. To accomplish this add the following to your vimrc:
 
<pre>
 
<pre>
 
function! InitPlugins()
 
function! InitPlugins()
Line 43: Line 43:
 
</pre>
 
</pre>
   
Now typing <tt>:qa</tt> in a tab will close out the tab.
+
Now typing <code>:qa</code> in a tab will close out the tab.
   
 
Note the use of a VimEnter autocmd instead of calling CmdAlias directly in the [[vimrc]]. This is done, because the plugin needs to be loaded before the functions defined in the plugin can be used. Since plugins are loaded ''after'' the .vimrc, VimEnter allows the plugin to load before the function is called.
 
Note the use of a VimEnter autocmd instead of calling CmdAlias directly in the [[vimrc]]. This is done, because the plugin needs to be loaded before the functions defined in the plugin can be used. Since plugins are loaded ''after'' the .vimrc, VimEnter allows the plugin to load before the function is called.

Latest revision as of 06:16, July 13, 2012

Tip 1247 Printable Monobook Previous Next

created 2006 · complexity basic · author hari_vim · version 7.0


Occasionally users will improperly use the commands :qa or :qa! instead of the proper :tabclose to close a tab in a session, quitting the entire session instead. A few methods can be used to remap the :tabclose command to a more memoriable command as outlined below.

Remap :tabclose to QAEdit

This method requires the plugin cmdalias.vim plugin. This plugin will allow you to keep your abbreviations in the context of a : command. Once this plugin is loaded add the following to your vimrc to create a user command for QA.

command! -bang QA :call TabQAll('<bang>')
function! TabQAll(bang)
  try
    if tabpagenr('$') > 1
      exec 'tabclose'.a:bang
    else
      exec 'qa'.a:bang
    endif
  catch
    echohl ErrorMsg | echo v:exception | echohl NONE
  endtry
endfunction

Finally create an abbreviation for :qa to mean :QA which will allow you to not have to remember :QA making it easier to use the command you are already familiar with to "close" your tab. To accomplish this add the following to your vimrc:

function! InitPlugins()
  call CmdAlias('qa', 'QA')
  au! InitPlugins VimEnter
endfunction

aug InitPlugins
  au!
  au VimEnter * :call InitPlugins()
aug END

Now typing :qa in a tab will close out the tab.

Note the use of a VimEnter autocmd instead of calling CmdAlias directly in the vimrc. This is done, because the plugin needs to be loaded before the functions defined in the plugin can be used. Since plugins are loaded after the .vimrc, VimEnter allows the plugin to load before the function is called.

Firefox Tab CloseEdit

Some users find it easier to map tab commands to the Firefox key-stroke patterns (Ctrl + T = New Tab, Ctrl + F4 = Close Tab). To do so, add the following to your vimrc:

"Vim 7 specific mappings
if version >= 700
  map <C-t> <Esc>:tabnew<CR>
  map <C-F4> <Esc>:tabclose<CR>
endif

See alsoEdit

CommentsEdit

Around Wikia's network

Random Wiki