Vim Tips Wiki
No edit summary
(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>inoremap II <Esc>I
+
<pre>
 
inoremap II <Esc>I
 
inoremap AA <Esc>A
 
inoremap AA <Esc>A
 
inoremap OO <Esc>O
 
inoremap OO <Esc>O
 
</pre>
 
</pre>
Those mappings stay in INSERT mode.
 
* <tt>II</tt> goes to the beginning of the line
 
* <tt>AA</tt> goes to the end of the line
 
* <tt>OO</tt> start a newline above the current line.
 
   
 
Those mappings stay in insert mode.
==Line Modifications==
 
  +
*<code>II</code> go to just before the first non-blank text of the line
 
*<code>AA</code> go to the end of the line
 
*<code>OO</code> start editing on a new line above the current line
  +
 
==Line modifications==
 
<pre>
 
<pre>
 
inoremap CC <Esc>C
 
inoremap CC <Esc>C
Line 20: Line 34:
 
inoremap UU <Esc>u
 
inoremap UU <Esc>u
 
</pre>
 
</pre>
* <tt>CC</tt> change what is on the right of the cursor
 
* <tt>SS</tt> change the whole line
 
* <tt>DD</tt> delete the current line (end in COMMAND mode)
 
* <tt>UU</tt> undo
 
   
 
*<code>CC</code> change what is on the right of the cursor
==File Commands==
 
 
*<code>SS</code> change the whole line
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.
 
 
*<code>DD</code> delete the current line (end in normal mode)
<pre>
 
 
*<code>UU</code> undo
inoremap WW <Esc>:w
 
  +
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

Tip 1646 Printable Monobook Previous Next

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 line
  • AA go to the end of the line
  • OO 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 cursor
  • SS change the whole line
  • DD delete the current line (end in normal mode)
  • UU undo

Comments[]