Wikia

Vim Tips Wiki

Changes: Insert in normal mode

Edit

Back to page

(Move categories to tip template)
(Remove html character entities)
 
Line 13: Line 13:
 
===Inserting an empty line===
 
===Inserting an empty line===
 
With the following map, you can press Enter in normal mode to insert an empty line.
 
With the following map, you can press Enter in normal mode to insert an empty line.
 
 
<pre>
 
<pre>
:nmap &lt;Enter&gt; _i&lt;Enter&gt;&lt;Esc&gt;
+
:nmap <CR> _i<Enter><Esc>
 
</pre>
 
</pre>
   
Line 23: Line 22:
 
" Enter a blank line below/above cursor in Normal mode.
 
" Enter a blank line below/above cursor in Normal mode.
 
" The o command will continue comments in a program.
 
" The o command will continue comments in a program.
nmap ,o o&lt;Esc&gt;k
+
nmap ,o o<Esc>k
nmap ,O O&lt;Esc&gt;j
+
nmap ,O O<Esc>j
 
</pre>
 
</pre>
   
Line 32: Line 31:
 
In normal mode, it inserts a space to push the rest of the line to the right, while leaving the cursor in the same position.
 
In normal mode, it inserts a space to push the rest of the line to the right, while leaving the cursor in the same position.
   
:nnoremap &lt;Space&gt; i&lt;Space&gt;&lt;Esc&gt;
+
:nnoremap <Space> i<Space><Esc>
   
 
For example, suppose we want foo to be aligned with bar:
 
For example, suppose we want foo to be aligned with bar:
Line 44: Line 43:
   
 
==Comments==
 
==Comments==
 
----
 

Latest revision as of 09:02, September 29, 2008

Tip 604 Printable Monobook Previous Next

created November 18, 2003 · complexity basic · author Sigurd/Yakov Lerner · version 5.7


Inserting an empty lineEdit

With the following map, you can press Enter in normal mode to insert an empty line.

:nmap <CR> _i<Enter><Esc>

Here is an alternative:

" Enter a blank line below/above cursor in Normal mode.
" The o command will continue comments in a program.
nmap ,o o<Esc>k
nmap ,O O<Esc>j

Inserting a spaceEdit

If you manually align text (declarations, ascii tables, trailing comments), you'll find this simple mapping useful.

In normal mode, it inserts a space to push the rest of the line to the right, while leaving the cursor in the same position.

:nnoremap <Space> i<Space><Esc>

For example, suppose we want foo to be aligned with bar:

int   foo;  // ...
double    bar;  // ...

Move the cursor just after 'int'. Press Space until 'foo' is aligned with 'bar'.

CommentsEdit

Around Wikia's network

Random Wiki