No edit summary |
JohnBeckett (talk | contribs) (Undo revision 34932 by 79.184.176.71 (talk) That's not useful.) |
||
(7 intermediate revisions by 3 users not shown) | |||
Line 1: | Line 1: | ||
+ | {{TipNew |
||
− | [[File:Placeholder|right|300px]] |
||
+ | |id=1646 |
||
− | A simple way to add commands in INSERT mode without having to use the escape key is to map double uppercase letters to theirs corresponding equivalents (lower or upper case) in COMMAND mode. |
||
+ | |previous=1645 |
||
+ | |next=1647 |
||
+ | |created=February 27, 2010 |
||
+ | |complexity=basic |
||
+ | |author=Bmx007 |
||
+ | |version=7.0 |
||
+ | |subpage=/201002 |
||
+ | |category1=Map |
||
+ | |category2= |
||
+ | }} |
||
+ | You can use CTRL-O or CTRL-\ CTRL-O (see {{help|ins-special-special}}) to execute a normal-mode command without leaving insert mode. But this is awkward for frequently used commands. Even mapping keys like <F5> or CTRL key combinations can be difficult to reach, and there are not many [[Mapping_keys_in_Vim_-_Tutorial_(Part_2)#Finding_unused_keys|available keys to map]]. If you want quick access to common normal-mode commands from insert mode, hitting <ESC> to actually go to normal mode may not be attractive. |
||
+ | |||
+ | You can [[Avoid the escape key]], but it can be faster to map double uppercase letters in insert mode to common commands. Most people don't use two uppercase letters in a row. If you do actually need to insert any text from these mappings, you can always type CTRL-V before the second character in the mapping ({{help|i_CTRL-V}}), or wait for the mapping to time out first. |
||
− | Here are some examples I found quite useful. |
||
==Quick movements== |
==Quick movements== |
||
− | <pre> |
+ | <pre> |
⚫ | |||
inoremap AA <Esc>A |
inoremap AA <Esc>A |
||
inoremap OO <Esc>O |
inoremap OO <Esc>O |
||
</pre> |
</pre> |
||
⚫ | |||
⚫ | |||
− | * <tt>AA</tt> goes to the end of the line |
||
⚫ | |||
⚫ | |||
⚫ | |||
+ | *<code>II</code> go to just before the first non-blank text of the line |
||
⚫ | |||
⚫ | |||
+ | |||
⚫ | |||
<pre> |
<pre> |
||
inoremap CC <Esc>C |
inoremap CC <Esc>C |
||
Line 20: | Line 34: | ||
inoremap UU <Esc>u |
inoremap UU <Esc>u |
||
</pre> |
</pre> |
||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
− | ==File Commands== |
||
⚫ | |||
− | The following mapping start entering a command but don't execute them until you press return. This is to prevent mistake by typing text containing such letters combination. |
||
⚫ | |||
− | <pre> |
||
⚫ | |||
⚫ | |||
+ | |||
− | inoremap ZZ <Esc>:wq |
||
− | inoremap EE <Esc>:e! |
||
− | </pre> |
||
− | * <tt>WW</tt> save the current file |
||
− | * <tt>EE</tt> revert the current file |
||
− | * <tt>ZZ</tt> save and quit. |
||
==Comments== |
==Comments== |
||
− | In case you really need to type the same uppercase letter twice, just wait a bit after typing the first one. |
Latest revision as of 10:23, 5 August 2012
created February 27, 2010 · complexity basic · author Bmx007 · version 7.0
You can use CTRL-O or CTRL-\ CTRL-O (see :help ins-special-special) to execute a normal-mode command without leaving insert mode. But this is awkward for frequently used commands. Even mapping keys like <F5> or CTRL key combinations can be difficult to reach, and there are not many available keys to map. If you want quick access to common normal-mode commands from insert mode, hitting <ESC> to actually go to normal mode may not be attractive.
You can Avoid the escape key, but it can be faster to map double uppercase letters in insert mode to common commands. Most people don't use two uppercase letters in a row. If you do actually need to insert any text from these mappings, you can always type CTRL-V before the second character in the mapping (:help i_CTRL-V), or wait for the mapping to time out first.
Quick movements[]
inoremap II <Esc>I inoremap AA <Esc>A inoremap OO <Esc>O
Those mappings stay in insert mode.
II
go to just before the first non-blank text of the lineAA
go to the end of the lineOO
start editing on a new line above the current line
Line modifications[]
inoremap CC <Esc>C inoremap SS <Esc>S inoremap DD <Esc>dd inoremap UU <Esc>u
CC
change what is on the right of the cursorSS
change the whole lineDD
delete the current line (end in normal mode)UU
undo