Vim Tips Wiki
(Uploaded by JohnBot from a locally edited file)
m (Flag duplicate 287)
Line 1: Line 1:
  +
{{Duplicate|287}}
 
{{TipImported
 
{{TipImported
 
|id=30
 
|id=30
Line 14: Line 15:
   
 
Ctrl-A is very useful in a macro. As an example, suppose you type the line:
 
Ctrl-A is very useful in a macro. As an example, suppose you type the line:
  +
<pre>
101 This is an item.
+
101 This is an item.
  +
</pre>
   
 
In Normal mode, enter the following to record a macro into the '''a''' register. This macro yanks the current line, then pastes it below, then increments the number.
 
In Normal mode, enter the following to record a macro into the '''a''' register. This macro yanks the current line, then pastes it below, then increments the number.
  +
<pre>
qa
+
qa
Y
+
Y
p
+
p
Ctrl-A
+
Ctrl-A
q
+
q
  +
</pre>
   
 
Now type '''15@a''' to perform the macro 15 times. You will see:
 
Now type '''15@a''' to perform the macro 15 times. You will see:
  +
<pre>
 
101 This is an item.
+
101 This is an item.
102 This is an item.
+
102 This is an item.
103 This is an item.
+
103 This is an item.
104 This is an item.
+
104 This is an item.
and so on
+
and so on
  +
</pre>
   
 
On Windows, your _vimrc file may source mswin.vim. That script sets Ctrl-A to Select All. If you want to use Ctrl-A in Normal mode to increment a number, you need:
 
On Windows, your _vimrc file may source mswin.vim. That script sets Ctrl-A to Select All. If you want to use Ctrl-A in Normal mode to increment a number, you need:
  +
:nunmap &lt;C-A>
 
  +
<pre>
 
:nunmap &lt;C-A>
  +
</pre>
   
 
==References==
 
==References==

Revision as of 08:16, 9 January 2008

Duplicate tip

This tip is very similar to the following:

These tips need to be merged – see the merge guidelines.

Tip 30 Printable Monobook Previous Next

created March 7, 2001 · complexity basic · author neuron · version 5.7


You can increment or decrement a number by pressing Ctrl-A or Ctrl-X when in Normal mode. The number can be at the cursor, or after the cursor.

The number can be decimal, hexadecimal or octal. You can also increment or decrement a single letter ("a...", "b...", "c..."). This is controlled with the 'nrformats' option.

Ctrl-A is very useful in a macro. As an example, suppose you type the line:

101 This is an item.

In Normal mode, enter the following to record a macro into the a register. This macro yanks the current line, then pastes it below, then increments the number.

qa
Y
p
Ctrl-A
q

Now type 15@a to perform the macro 15 times. You will see:

101 This is an item.
102 This is an item.
103 This is an item.
104 This is an item.
and so on

On Windows, your _vimrc file may source mswin.vim. That script sets Ctrl-A to Select All. If you want to use Ctrl-A in Normal mode to increment a number, you need:

:nunmap <C-A>

References

Comments