4 ms·
Here's a good tip I picked up recently when working with numbers: Increment a number on or after the cursor with Ctrl-A and decrement with Ctrl-X in normal mod
by oacgnol 15y ago
Here's a good tip I picked up recently when working with numbers:
Increment a number on or after the cursor with Ctrl-A and decrement with Ctrl-X in normal mode. Saves a few keystrokes over having to replace or enter insert mode.
- tyrmored 15y agoYou can prepend a count to that too, to increment/decrement by a fixed amount. This gets scary useful when you use tpope's speeddating plugin.
- ilikepi 15y agoI've been using those more and more recently and have noticed a couple interesting things to be aware of. First, Vim interprets a dash character immediately preceding the number as a negative sign. (In playing around a bit I suspect this behavior is slightly influenced by the syntax rules for the particular filetype you're working with.) The effect of this is to flip the behavior of CTRL-A and CTRL-X. Secondly, if the first digit of the number is '0', Vim will behave as if the number is octal, so incrementing "07" once will result in "010". Similarly, a prefix of "0x" or "0X" will cause a number to be treated as hex.
- johncoltrane 15y agoTo avoid the "07" -> "010" problem you can add set nrformats-=octal to your .vimrc.
- Nick_C 15y agoJust be aware if you are in a screen session, ctrl-a ctrl-x chord will lock the screen. It bit me only an hour ago.