History
Article Edit this page Discussion

Tabclose instead of quit-all

From Vim Tips Wiki

(Redirected from VimTip1247)
Jump to: navigation, search

Tip 1247 Previous Next Created: June 2, 2006 Complexity: basic Author: hari_vim Version: n/a


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. 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.

[edit] Comments

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

Rate this article:

Share this article:

Hubs Highlights International Sites Wikia messages
Entertainment
Gaming
Cartoons & Comics
Science Fiction
Hobbies
Sports
See all...
Grand Theft Auto
Pixar
Legend of Zelda Wiki
Terminator Wiki
Everquest II Wiki
Dark Shadows
German
Spanish
Chinese
Japanese
More...
Wikia is hiring for several open positions


Vote for collaboration of the month.

Send this article to a friend
"Tabclose instead of quit-all"
 
 
Hi!

I thought you'd like this page from Wikia!

http://vim.wikia.com

Come check it out!
Send confirmation