If I use Ctrl-A to increment (or Ctrl-X to decrement) a hex number, the resulting number will be written with lowercase letters, unless there were uppercase letters in the original number.
For example, if I increment 0x009
, I get 0x00a
; but if I increment 0xA09
, I get 0xA0A
.
I want it to default to using capital letters. Does anyone know how to do this? Does anyone else care?
One tricky way:
:nnoremap <C-A> m'<C-A>vUgUTx``
Explanation:
m' # Create a mark on digit to increment.
<C-A> # Control-A
v # Visual select current letter.
U # Set visual selection (current letter) to uppercase.
gUTx # Set to uppercase (gU) next movement: (Tx) from current position to previous 'x' letter.
`` # Go to position of previous mark.
So this way creates a small different behaviour from original <C-A>
, for example, in this case:
A hex number 0x0ba in lowercase.
^--- Cursor position
Will set 0x0ba
in 0x0BB
but cursor will come back to letter n
from number
, insteat setting its position in the number incremented. You can play with marks to change this behaviour. I hope this can help.
One can prefix hexadecimal constants with 0X
instead of 0x
in
order to make Vim use capital letters when adding to or subtracting
from them via the Ctrl+A and Ctrl+X commands.
Not a perfect solution, but oftentimes it is easier to change the prefix of the affected number to Vim’s liking, increment or decrement it, and then change the prefix back, than to recall how to do that in a general way instead.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With