Making Vim use capital letters when incrementing hexadecimal numbers with Ctrl-A
vim
Solution
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.
Problem
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?