Tip: #1247 - Tabclose instead of quit-all
Created: June 2, 2006 12:47 Complexity: basic Author: hari_vim at yahoo dot com Version: n/a Karma: 8/2 Imported from: Tip#1247
If you are like me, you might have already used :qa or :qa! to mean :tabclose instead of quitting the whole session for a shock. I decided to solve this problem as I thought this might be in for a repetion, so here is my workaround. You need cmdalias.vim plugin for this trick to work.
- First create a user command, say QA. Put the below in your vimrc
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
- Create an abbreviation for :qa to mean :QA such that you don't have to remember to say :QA (if you have to remember, it totally defeats this exercise). This is where you need the cmdalias plugin. It is a very simple (and so, very small) plugin to make sure the abbreviation works only in the : mode and at the start of the command (so "qa" while typing as part of a filename will not possibly become "QA"). Put this in your vimrc:
function! InitPlugins() call CmdAlias('qa', 'QA') au! InitPlugins VimEnter endfunction aug InitPlugins au! au VimEnter * :call InitPlugins() aug END
The VimEnter approach is required because, the CmdAlias()
function will not be available while vimrc is being sourced.
Comments
Hi,
Instead i chose to map the firefox key-stroke to Vim (Ctrl+T -- New Tab, Ctrl+F4 -- Close tab).
"Vim 7 specific mappings if version >= 700 map <C-t> <Esc>:tabnew<CR> map <C-F4> <Esc>:tabclose<CR> endif
- Mayuresh
mskadu at gmail.com , June 16, 2006 1:57
TO DO: rename the tip
--Luc Hermitte 11:43, 12 September 2007 (UTC)