How to make a text file with a pattern of hex numbers in increasing order using VIM?

StackOverflow https://stackoverflow.com/questions/23074763

  •  03-07-2023
  •  | 
  •  

Domanda

How we can make a text file with a pattern of hex numbers in increasing order using the VIM editor? I need a pattern like below:

0000
0001
0002
....
0008
0009
000A
000B
....
000F
0010
0011
....
FFFF

is it possible with repeat operation?

È stato utile?

Soluzione 2

One solution would be to create a macro. <c-a> will increment the number under the cursor by 1. If the number starts with a 0x it will be interpreted as a a hex number.

From the documentation :h CTRL-A

The CTRL-A command is very useful in a macro.  Example: Use the following
steps to make a numbered list.

1. Create the first list entry, make sure it starts with a number.
2. qa        - start recording into register 'a'
3. Y         - yank the entry
4. p         - put a copy of the entry below the first one
5. CTRL-A    - increment the number
6. q         - stop recording
7. <count>@a - repeat the yank, put and increment <count> times

After words you might need to remove 0x from the numbers and make them upper case.

Altri suggerimenti

:put =map(range(0,65535), 'printf(''%04x'', v:val)')
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top