# How can I repeat a command a hexadecimal number of times?

The file I'm working on contains a hexdump. I pulled it directly out of memory, so it starts from an arbitrary offset, like this:

``````0x1234: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x1244: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x1254: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x1264: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
``````

I want to "rebase" this hexdump so it looks like this:

``````0x0000: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0010: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0020: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0030: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
``````

This means I need to subtract the value 0x1234 from each of those values. My current workflow looks like this:

1. Fire up a python interpreter and convert 0x1234 to base-10 (it's 4660)
2. Position the cursor over the first 0x1234 in my file
3. Input `4660`Ctrl-x
4. Repeatedly input `j.` until I've hit all the lines

That first step is really annoying - since I'm working with hexadecimal numbers, it feels like I ought to be able to subtract a hexadecimal value directly, rather than converting via base-10.

Is there an easier way to do this?

I would do:

`:execute "normal! `Ctrl-r=`Ox1234`Enter`\<C-x>"`

The r= use the expression register. It let you enter an expression that Vim will convert and paste.

To repeat it you can use the same technique: `j.` but you could also record a macro and run it 1000 times:

Record the macro in register `a`:

`qaj.a`

Run it 1000 times:

`1000@a`

• Also `:global/^0x/normal! <C-r>=0x1234<Enter><C-v><C-x>` (all `<>` keystrokes as actual keypresses) Commented Dec 8, 2022 at 17:29