Tip #30: Increasing or decreasing numbers
tip karma |
Rating 303/100, Viewed by 5465
|
Read and edit this tip on the
Vim tip wiki.
The wiki may have a more recent version of this tip.
created: |
|
March 7, 2001 5:25 |
|
complexity: |
|
basic |
author: |
|
neuron |
|
as of Vim: |
|
5.7 |
To increase a number under or nearest to the right of the cursor, go to Normal mode and type:
Ctrl-A
To decrease, type:
Ctrl-X
Using this in a macro simplifies generating number sequences a lot.
<< reverse all the line with only 7 keystroke in vim |
Find and Replace >>
Additional Notes
[email protected],
October 10, 2001 0:30
|
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
|
[email protected],
October 10, 2001 0:31
|
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
|
[email protected],
February 18, 2003 0:57
|
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
|
[email protected],
May 15, 2003 7:01
|
you just have to put
nunmap <C-A>
in your _vimrc file
Seib
|
[email protected],
November 30, 2003 6:05
|
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
|
sbbrouwer#gmail,com,
May 8, 2006 1:15
|
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
|
[email protected],
May 31, 2006 9:43
|
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.
|
|