No edit summary |
(Change <tt> to <code>, perhaps also minor tweak.) |
||
(12 intermediate revisions by 5 users not shown) | |||
Line 1: | Line 1: | ||
+ | {{TipImported |
||
− | {{review}} |
||
− | {{Tip |
||
|id=1247 |
|id=1247 |
||
+ | |previous=1245 |
||
− | |title=Did you mean |
||
+ | |next=1249 |
||
− | |created= |
+ | |created=2006 |
|complexity=basic |
|complexity=basic |
||
− | |author=hari_vim |
+ | |author=hari_vim |
− | |version= |
+ | |version=7.0 |
|rating=8/2 |
|rating=8/2 |
||
+ | |category1=Plugin |
||
− | |text= |
||
+ | |category2=Tabs |
||
− | 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 [/scripts/script.php?script_id=745 vimscript #745] cmdalias.vim plugin for this trick to work. |
||
− | |||
− | |||
− | |||
− | - First create a user command, say QA. Put the below in your vimrc |
||
− | |||
⚫ | |||
− | |||
⚫ | |||
− | |||
− | try |
||
− | |||
⚫ | |||
− | |||
⚫ | |||
− | |||
− | else |
||
− | |||
⚫ | |||
− | |||
⚫ | |||
− | |||
− | catch |
||
− | |||
⚫ | |||
− | |||
− | endtry |
||
− | |||
⚫ | |||
− | |||
− | |||
− | |||
− | - 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: |
||
− | |||
− | |||
− | |||
⚫ | |||
− | |||
⚫ | |||
− | |||
⚫ | |||
− | |||
⚫ | |||
− | |||
− | |||
− | |||
⚫ | |||
− | |||
⚫ | |||
− | |||
⚫ | |||
− | |||
⚫ | |||
− | |||
− | |||
− | |||
− | The VimEnter approach is required because, the CmdAlias() function will not be available while vimrc is being sourced. |
||
}} |
}} |
||
+ | 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== |
+ | 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>. |
||
− | The link to the script was wrong. Correct link is http://www.vim.org/scripts/script.php?script_id=746 ([/scripts/script.php?script_id=746 vimscript #746]) |
||
+ | <pre> |
||
⚫ | |||
⚫ | |||
+ | try |
||
⚫ | |||
⚫ | |||
+ | else |
||
⚫ | |||
+ | endif |
||
+ | catch |
||
⚫ | |||
+ | endtry |
||
⚫ | |||
+ | </pre> |
||
+ | 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: |
||
− | hari_vim at yahoo dot com |
||
+ | <pre> |
||
− | , June 9, 2006 13:54 |
||
⚫ | |||
− | ---- |
||
⚫ | |||
− | Hi, |
||
⚫ | |||
⚫ | |||
⚫ | |||
− | Instead i chose to map the firefox key-stroke to Vim (Ctrl+T -- New Tab, Ctrl+F4 -- Close tab). |
||
⚫ | |||
⚫ | |||
⚫ | |||
+ | </pre> |
||
+ | Now typing <code>:qa</code> in a tab will close out the tab. |
||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
− | endif |
||
+ | 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. |
||
− | - Mayuresh |
||
+ | ==Firefox Tab Close== |
||
− | mskadu at gmail.com |
||
+ | 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: |
||
− | , June 16, 2006 1:57 |
||
+ | <pre> |
||
− | ---- |
||
⚫ | |||
− | While ctrl-t open effectively a new tab , ctrl-F4 dont close any ... dont know why tho. |
||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
+ | </pre> |
||
+ | ==See also== |
||
+ | *[[Replace a builtin command using cabbrev]] tells you how to accomplish something similar to {{script|id=746|text=cmdalias.vim}} without the plugin |
||
+ | ==Comments== |
||
− | '''Anonymous''' |
||
− | , June 18, 2006 9:32 |
||
− | ---- |
||
− | <!-- parsed by vimtips.py in 0.497559 seconds--> |
Latest revision as of 06:16, 13 July 2012
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 QA[]
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 Close[]
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 also[]
- Replace a builtin command using cabbrev tells you how to accomplish something similar to cmdalias.vim without the plugin