First use VIM to open the file that needs to be edited or viewed in binary format, not using the-B parameter sometimes results in a conversion error, as described in the post-divider section.
Vim-b File-to-open.dat
Then use XXD to convert the file into hexadecimal format
:%!xxd
The conversion appears similar to the following
0000000:5036 0a35 3932 2033 3230 0a32 3535 0a20 P6.592 320.255.
0000010:190E 2019 0e20 190e 2019 0e20 190e 2019.. .. .. .. .. .
0000020:0e20 190e 2019 0e1f 180c 1f18 0c1f 180c. .. ...........
0000030:1f18 0c1f 180c 1f18 0c1f 180c 1f18 0c27 ....... '
0000040:1b0d 261a 0c24 1b0e 2319 0d22 180e 2017.. &, .... $.. #..".. .
0000050:0c1f 180c 1e16 0b25 1d16 251d 1620 1a13 ....... %.. ..
You can now view and edit binary files just like normal text.
Modifying the hexadecimal content does not cause the right character to change, but the text on the right is only for your reference, and the changes are then converted back to binary 16, which are ignored.
Modify completion use XXD to convert the 16 binary back into binary:
:%!xxd-r
only 16 binary modifications will take effect.
Sub-********** isolated ********** line ****************
VIM Displays hexadecimal error
Use vim to open JPG files under Linux, using%! Xxd A 16 binary display, the file header is displayed as "3f3f
3f3f 0011 0804″ file end is displayed as "3f3f
0a "and the same operation under Windows is displayed as" Ffd8 ffc0 0011 0804″ and "ffd9
0a ", this is the correct JPEG file header and file tail flag.
It's weird!
At first, I thought it was JPEG under Windows and Linux is a different file header, and then remove the jpg suffix, a pure file, the phenomenon is still. Consider the differences that may not be the operating system.
Re-use Ghex to open JPEG Data View, found to show normal, "Ffd8 ffc0 0011
0804″ and "Ffd9 0a", right.
It's supposed to be a vim problem.
What is the ASCII code for 3f? , which indicates that VIM does not parse the file header and tail correctly, is it related to the encoding format used when Vim parses the file?
Open the. VIMRC configuration item and block out the following sentence:
Set Fileencodings=utf-8,gb2312,gbk,gb18030,ucs-bom
Then use VIM to open the JPEG file, display "Ffd8 ffc0 0011 0804″ and" Ffd9 0a ",
displayed correctly.
Originally, in order to support the identification and display of Chinese, I set the fileencodings of Vim,
When Vim opens the file, it will use the specified encoding format to parse the data, but the JPEG file header FFD8, tail FFD9
Not any one of the Chinese code, vim can not find the corresponding Chinese characters, it is displayed as?? , namely: 3f3f.
At this point, the confusion is all open.
Vim modifies binary files