Vim file editing with 16 binary

Source: Internet
Author: User

using vim to edit binary files is the first through the external program xxd to dump the file into the second binary text form, and then you can edit the file in the usual way, editing, and then using XXD conversion to the original form.

Can be divided into the following steps:

(1) First edit this file in binary mode: vim -B datafile

(2) Now use XXD to convert this file into 16 binary::%!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,.. 4^.00000020:373b 2731 0b22 0ca6 c1a2 d669 1035 39d9 7; ' 1. "..... i.59.

Now you can read and edit the text as you wish. Vim treats this information as plain text. Modifying the hexadecimal section does not result in a change in the part of the character that can be displayed, or vice versa.

(3) Finally, use the following command to convert it back::%!xxd-r

Only 16 of the modifications in the binary section will be used. Changes to the right can display text portions that are ignored.

Xxd is a command of Linux,VIM edits binary files (

*23.4* binary Files

You can use Vim to design for this purpose, so there are a number of limitations. But you can read a file, change a character, and then save it to disk. The result is that only one character is changed for your file, and the others are exactly the same as the original one.

To ensure that Vim is added with the "-B" parameter:

This parameter sets the ' binary ' option. Its role is to exclude all unintended side effects. For example, ' TextWidth ' is set to zero so that text lines are not allowed to be typeset. Also, files are read in Unix file format.

Binary mode can be used to modify a program's message messages. Be careful not to insert or delete any characters, which can cause the program to run into problems. Use the "R" command to enter the replacement mode.

Many of the characters in the file are not displayed. Display their values in HEX format:

: Set Display=uhex

Alternatively, you can use the command "GA" to display the character values under the cursor. When the cursor is on a <Esc> character, the output of the command looks like this:

<^[>  , Hex 1b,  

There may not be so many line breaks in the file. You can turn off the ' wrap ' option to get an overview of the effects:

        : Set nowrap
Byte position:

To find the current byte position in your file, use this command:

G Ctrl-g

Its output is lengthy:

    

The last two digits are the current byte position in the file and the total number of file bytes. This has taken into account the effect of the ' fileformat ' option causing different line break bytes.

To move to a specified byte in a file, use the "Go" command. For example, to move to byte 2345:

2345go
using Xxd:
A true binary editor is a two-way display of text: binary and hexadecimal format. You can  achieve this effect by converting the program "Xxd" in. The program is published with the. 

First edit this file in binary mode:

Now use XXD to convert this file into 16 binary:

        :%!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  

Now you can read and edit the text as you wish. Vim treats this information as plain text. Modifying the hexadecimal section does not result in a change in the part of the character that can be displayed, or vice versa.

Finally, use the following command to convert it back:

:%!xxd-r

Only 16 of the modifications in the binary section will be used. Changes to the right can display text portions that are ignored.

Vim file editing with 16 binary

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.