Best Seemingly Useless VIM Trick Ever
At some point this summer, I discovered the vim commands Ctrl+A and Ctrl+X. In normal mode, they find the first number on the current line and increment and decrement it, respectively.
What’s your first thought when you read that? Mine was “Why the heck is that useful enough to be included as default functionality? How often can you need that? That is a complete waste of a keybinding and is just confusing.”
Well, I stand partially corrected. It is not completely useless. I have found myself using it several times in the last month or so. My favorite use case is for making lists:
First, type
1. Some list element.
Then, in normal mode, record the following macro:
qa
Y
p
Ctrl-A
qNow, 10@a will perform the macro 10 times, copying the line and auto-incrementing the number each time.
1. Some list element. 2. Some list element. 3. Some list element. 4. Some list element. ... etc.
Neat! I’m still not entirely convinced it’s actually useful, but its cute nonetheless.
February 5th, 2011 at 7:05 pm
it works with hex and signed numbers as well:
http://vimdoc.sourceforge.net/htmldoc/change.html