Vim modify binary files

Source: Internet
Author: User
To modify a binary file, use vim to open the file to be edited or viewed in binary format. if you do not use the-B parameter, conversion errors may occur. for details, refer to the section after the separator line. Www.2cto. comvim-bfile-to-open.dat and then use xxd to convert the file into hexadecimal Format: %! Xxd conversion... vim to modify the binary file first use vim to open the file to be edited or viewed in binary format. if The-B parameter is not used, conversion errors may occur. for details, refer to the part after the separator line. Www.2cto.com vim-B file-to-open.dat and then use xxd to convert the file into hexadecimal format: %! After xxd conversion, it is shown as follows: 0000000 0a35 5036 3932 2033 0a32 3230 0a20 P6.592 320.00000000010: 0000e 3535 0e20 0000e 2019 0e20 0000e 2019 ........... 0000020: 0e20 127e 2019 0e1f 180c 1f18 0c1f 180c .............. 0000030: 1f18 0c1f 180c 1f18 0c1f 180c 1f18 0c27 ............... '1970: 1b0d 261a 0c24 1b0e 0000040 0d22 180e 2319 .. &.. $ .. #.. "... 0000050: 0c1f 180c 1e16 0b25 1d16 251d 1620 1a13 ....... % .. %... Now you can view and edit binary files like normal text. Modifying the hexadecimal content will not change the characters on the right side. In fact, the text on the right side is for your reference only. if you modify the content, convert the hexadecimal format back to the binary format. all these modifications will be ignored. After www.2cto.com is modified, use xxd to convert the hexadecimal format back to the binary: %! Xxd-r takes effect only when the hexadecimal system is modified. * ********************************** Line * * ************** VIM displays a hexadecimal error. in linux, use vim to open a jpg file, use %! When xxd is displayed in hexadecimal notation, the file header is displayed as "3f3f3f3f 0011 0804" and the end of the file is displayed as "3f3f0a". the same operation is performed in windows, it is displayed as "ffd8 ffc0 0011 0804" and "ffd90a". This is the correct jpeg file header and file tail mark. Strange! At the beginning, I thought that jpeg is a different file header in windows and linux. later I removed the jpg suffix, which is a pure file. It may not be a difference in the operating system. Re-use ghex to open the jpeg data and check that the displayed data is normal, which is "ffd8 ffc0 00110804" and "ffd9 0a", correct. Www.2cto.com is probably a problem with vim. What is the 3f ascii code ?, It indicates that vim does not parse the file header and tail properly. is it related to the encoding format used by vim to parse the file? Open. the vimrc configuration item shields the following sentence: set fileencodings = UTF-8, gb2312, gbk, gb18030, and ucs-bom. then use vim to open the jpeg file, "ffd8 ffc0 0011 0804" and "ffd9 0a" are displayed. Originally, in order to support recognition and display of Chinese characters, I defined the fileencodings of vim. when vim opened the file, it used the specified encoding format to parse the data, unfortunately, the jpeg file header FFD8 and the end FFD9 are not any Chinese Encoding. vim cannot find the corresponding Chinese text and it is displayed ??, That is, 3f3f. So far, all puzzles are opened.
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.