Use Vim View and edit a binary file
VimYou can easily edit binary files. I personally think it is better than Emacs's binary editing method.VimBinary files are edited by externalProgramXxd to dump the file into its binary text form, then you can edit the file according to the normal editing method, after editing, then use xxd to convert it to the original form.
You can perform the following steps:
(1) first edit the file in binary mode:Vim-B datafile
(2) now use xxd to convert the file to hexadecimal: %! Xxd
The text looks like this:
0000000: 1f8b 0808 39d7 173b 0203 7474 002b 4e49 .... 9 ..;.. TT. + ni0000010: 4b2c 8660 eb9c ECAC c462 eb94 345e 2e30 K ,. '..... B .. 4 ^. 00000020: 373b 2731 0b22 0ca6 c1a2 d669 1035 39d9 7; '1. "..... I .59.
Now you can read and edit the text as you like.VimTreat the information as plain text. Changing the hexadecimal part does not change the printable character part, and vice versa.
(3) Finally, use the following command to convert it back: %! Xxd-R
Only the modification of the hexadecimal part will be used. The modification of the text area displayed on the right is negligible.
Xxd is a Linux Command,VimYou can use "!" To call external commands, the function is to perform a hexadecimal dump or vice versa.
Vim Edit a binary file ( Vim Manual recording)
* 23.4 * binary files
You can useVimTo edit binary files.VimThis is not designed for this purpose, so there are several limitations. But you can read a file, change a character, and save it on disk. The result is that only the character in your file is changed, and the others are exactly the same as the original one.
Make sure thatVimDo not use the clever tips to start
VimAdd the "-B" parameter:
Vim-B datafile
This parameter sets the 'binary 'option. Its role is to exclude all unexpected side effects. For example, 'textidth' is set to zero, so that text lines are not typographical. In addition, all files are read in UNIX format.
Binary mode can be used to modify the message of a program. Be careful not to insert or delete any characters, which will cause program running problems. Run the "r" command to enter the replacement mode.
Many characters in the file are not displayed. Display their values in hex format:
: Set display = uhex
You can also run the "Ga" command to display the character values under the cursor. When the cursor is placed on a <ESC> character, the output of this command looks like this:
<^ [> 27, Hex 1B, octal 033
There may not be so many line breaks in the file. You can turn off the 'wrapp' option to get the overall effect:
: Set nowrap
Byte location
To find your current byte location in the file, run the following command:
G CTRL-G
The output is very lengthy:
COL 9-16 of 9-16; line 277 of 330; Word 1806 of 2058; byte 10580 of 12206
The last two digits are the current location of the byte in the file and the total number of bytes in the file. This has taken into account the effect of the 'fileformat' option on line breaks.
To move a specified byte to a file, run the "go" command. For example, to move to byte 2345:
2345go
Use xxd
A real binary editor displays text in two ways: Binary and hexadecimal formats. You canVimThrough the Conversion Program "xxd" to achieve this effect. This program is
VimReleased together.
First, edit the file in binary mode:
Vim-B datafile
Now we use xxd to convert this file into a hexadecimal format:
: %! Xxd
The text looks like this:
0000000: 1f8b 0808 39d7 173b 0203 7474 002b 4e49 .... 9 ..;.. TT. + Ni 0000010: 4b2c 8660 eb9c ECAC c462 eb94 345e 2e30 K ,. '..... B .. 4 ^. 0 0000020: 373b 2731 0b22 0ca6 c1a2 d669 1035 39d9 7; '1. "..... I .59.
Now you can read and edit the text as you like.VimTreat the information as plain text. Changing the hexadecimal part does not change the printable character part, and vice versa.
Finally, use the following command to convert it back:
: %! Xxd-R
Only the modification of the hexadecimal part will be used. The modification of the text area displayed on the right is negligible.