Home Explore Blog CI



neovim

4th chunk of `runtime/doc/usr_23.txt`
c5748293735e0bddbbbdee2a7ffb9c2ac299bb5bf33ab7d60000000100000bd6
 the wrong way, add
the "-b" argument when starting Vim: >

	vim -b datafile

This sets the 'binary' option.  The effect of this is that unexpected side
effects are turned off.  For example, 'textwidth' is set to zero, to avoid
automatic formatting of lines.  And files are always read in Unix file format.

Binary mode can be used to change a message in a program.  Be careful not to
insert or delete any characters, it would stop the program from working.  Use
"R" to enter replace mode.

Many characters in the file will be unprintable.  To see them in Hex format: >

	:set display=uhex

Otherwise, the "ga" command can be used to see the value of the character
under the cursor.  The output, when the cursor is on an <Esc>, looks like
this:

	<^[>  27,  Hex 1b,  Octal 033 ~

There might not be many line breaks in the file.  To get some overview switch
the 'wrap' option off: >

	:set nowrap


BYTE POSITION

To see on which byte you are in the file use this command: >

	g CTRL-G

The output is verbose:

    Col 9-16 of 9-16; Line 277 of 330; Word 1806 of 2058; Byte 10580 of 12206 ~

The last two numbers are the byte position in the file and the total number of
bytes.  This takes into account how 'fileformat' changes the number of bytes
that a line break uses.
    To move to a specific byte in the file, use the "go" command.  For
example, to move to byte 2345: >

	2345go


USING XXD

A real binary editor shows the text in two ways: as it is and in hex format.
You can do this in Vim by first converting the file with the "xxd" program.
This comes with Vim.
   First edit the file in binary mode: >

	vim -b datafile

Now convert the file to a hex dump with xxd: >

	:%!xxd

The text will look 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. ~

You can now view and edit the text as you like.  Vim treats the information as
ordinary text.  Changing the hex does not cause the printable character to be
changed, or the other way around.
   Finally convert it back with:
>
	:%!xxd -r

Only changes in the hex part are used.  Changes in the printable text part on
the right are ignored.

See the manual page of xxd for more information.

==============================================================================
*23.4*	Compressed files

This is easy: You can edit a compressed file just like any other file.  The
"gzip" plugin takes care of decompressing the file when you edit it.  And
compressing it again when you write it.
   These compression methods are currently supported:

	.Z	compress
	.gz	gzip
	.bz2	bzip2

Vim uses the mentioned programs to do the actual compression and
decompression.  You might need to install the programs first.

==============================================================================

Next chapter: |usr_24.txt|  Inserting quickly

Copyright: see |manual-copyright|  vim:tw=78:ts=8:noet:ft=help:norl:

Title: Editing Binary Files and Compressed Files in Vim
Summary
This section continues discussing how to edit binary files in Vim. It explains how to open a binary file using "vim -b datafile", which sets the 'binary' option. It covers how to view unprintable characters in hex format using ":set display=uhex" and how to determine the byte position using "g CTRL-G". It also describes using the "xxd" program to convert a file to a hex dump for easier editing. Finally, the section explains how to edit compressed files, noting that Vim's "gzip" plugin automatically handles decompression and compression for .Z, .gz, and .bz2 files, relying on external compression programs.