No edit summary |
(Clean and reword.) |
||
Line 1: | Line 1: | ||
− | {{review}} |
||
{{Tip |
{{Tip |
||
|id=30 |
|id=30 |
||
Line 9: | Line 8: | ||
|rating=274/87 |
|rating=274/87 |
||
|text= |
|text= |
||
+ | 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. |
||
− | To increase a number under or nearest to the right of the cursor, go to Normal mode and type: |
||
+ | 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 |
||
⚫ | |||
+ | q |
||
+ | Now type '''15@a''' to perform the macro 15 times. You will see: |
||
− | To decrease, type: |
||
+ | 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: |
||
⚫ | |||
+ | == References == |
||
− | |||
⚫ | |||
− | Using this in a macro simplifies generating number sequences a lot. |
||
+ | :help 'nrformats' |
||
− | |||
}} |
}} |
||
== Comments == |
== Comments == |
||
− | I always looked for a possbility to create multiple lines with the same content only differing by an increasing or decreasing number. Probably haven't searched hard enough: |
||
− | |||
− | Create the first line with the number. |
||
− | Set the cursor on the number. |
||
− | Do: mnYP`n^A |
||
− | |||
− | Or create a macro with this and call it multiple times. The single quote must be the back quote ` not ', because ' goes to the beginning of the line in the mark and ` goes to the proper column/character-position. Furthermore the ^A = <CTRL>-A (see this page). You can as easily change to decreasing numbers. |
||
− | |||
− | Herman Suijs |
||
− | |||
− | |||
− | vim--AT--suijsmail.com |
||
− | , October 10, 2001 0:30 |
||
− | ---- |
||
− | I didn't even read properly, because the nearest number to the right is increased or decreased. If there is only 1 number on the line it doesn't matter if you use ` or '. |
||
− | |||
− | Sorry ;-) |
||
− | |||
− | Herman Suijs |
||
− | |||
− | |||
− | vim--AT--suijsmail.com |
||
− | , October 10, 2001 0:31 |
||
− | ---- |
||
− | Hi all |
||
− | |||
− | CTRL-A is used to add a number. |
||
− | However, in gvim for win32, it became "select all". |
||
− | |||
− | Is there any way to change it back to increase a number instead of select all text in file? |
||
− | |||
− | Thanks |
||
− | |||
− | franklin--AT--goodhorse.idv.tw |
||
− | , February 18, 2003 0:57 |
||
− | ---- |
||
− | you just have to put |
||
− | |||
⚫ | |||
− | |||
− | in your _vimrc file |
||
− | Seib |
||
− | |||
− | seibpoirier--AT--free.fr |
||
− | , May 15, 2003 7:01 |
||
− | ---- |
||
− | Actually, that last comment won't work on win32. (at least when I tried it) |
||
− | The correct version of that is: |
||
− | |||
− | :unmap <c-a> |
||
− | |||
− | Hope this helps someone else. :-) |
||
− | |||
− | - Mick |
||
− | |||
− | |||
− | micklweiss--AT--gmx.net |
||
− | , November 30, 2003 6:05 |
||
− | ---- |
||
− | Actually, that version does work --- in normal mode. Net. effect: |
||
− | In normal mode, c-A increments. |
||
− | In insert mode (or any other mode), c-A selects all. |
||
− | Wicked! |
||
− | |||
− | --Esteis |
||
− | |||
− | |||
− | sbbrouwer#gmail,com |
||
− | , May 8, 2006 1:15 |
||
− | ---- |
||
− | If you are trying to make this work in Windows, look into your _vimrc file. There is a line there that sources a file called mswin.vim, this maps a whole mess of things to try to make things work like normal Windows editors do (Ctrl-C for Copy, Ctrl-P for Paste, and so on) -- if this is not the way you want things to work, just remove the line that sources that file. |
||
− | |||
− | seftarbell--AT--gmail.com |
||
− | , May 31, 2006 9:43 |
||
− | ---- |
||
− | <!-- parsed by vimtips.py in 0.580948 seconds--> |
Revision as of 05:50, 16 June 2007
Tip: #30 - Increasing or decreasing numbers
Created: March 7, 2001 5:25 Complexity: basic Author: neuron Version: 5.7 Karma: 274/87 Imported from: Tip#30
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
:help Ctrl-A :help 'nrformats'