Skip to main content
13 votes

How to edit binary files with Vim?

TL;DR Answer Open the file with Vim in binary mode: vim -b <file_to_edit> In Vim, get into hex editing mode like so: :%!xxd -p To save: :%!xxd -p -r :w The first line will convert the ...
Hintron's user avatar
  • 239
11 votes

Jumping to a byte offset, and displaying position as byte offset

You can hit g Ctrl+g and you get the full information about the position: Col 13 of 35; Line 18 of 2272; Word 70 of 7767; Char 410 of 50021; Byte 410 of 50118
Vivian De Smedt's user avatar
10 votes
Accepted

How to open *.dia files as *.gz files?

If we look at /usr/share/vim/vim80/plugin/gzip.vim we can see how the plugin does this: augroup gzip " Remove all gzip autocommands au! " Enable editing of gzipped files. " The functions are ...
Martin Tournoij's user avatar
9 votes

How to edit binary files with Vim?

Use the "bvi" editor. http://bvi.sourceforge.net/ (It's in every Linux repository.) $ apt-cache show bvi [snip] Description-en: binary file editor The bvi is a display-oriented editor for binary ...
RonJohn's user avatar
  • 191
7 votes

Where is xxd in Windows gvim?

It is distributed with Vim (as xxd.exe), along with diff.exe. So it exists and should work on Windows. You don't need to install anything separately, as it is already bundled with Vim (at least in ...
mMontu's user avatar
  • 6,640
7 votes
Accepted

Why does Vi change the size of my .bin file?

Most likely, Vi adds a trailing linefeed. There used to be whole flame wars whether editors should add a trailing linefeed for the content. It is a convention, that differs between Windows (there you ...
Christian Brabandt's user avatar
5 votes

How to force Vim to open given file as another filetype? (e.g. .txt.gz?)

There are two answers to your question: General In order to open a file, overriding the default filetype detection, you can just specify a :setf[iletype] command as part of :edit. For example: :...
Ingo Karkat's user avatar
  • 17.9k
3 votes

How to edit a readonly zip file?

Vim ships with the zip plugin (:help pi_zip) that lets you automatically browse and edit the contents of the zip file. These browse buffers are read-only. In order to read the actual zip file, you ...
Ingo Karkat's user avatar
  • 17.9k
3 votes

Jumping to a byte offset, and displaying position as byte offset

To display the byte position you can use the following command :echo line2byte(line("."))+col(".")-1 See Question: Get offset of current buffer in vim
Vivian De Smedt's user avatar
3 votes
Accepted

Why is `%!xxd -r` result wrong while `xxd -r` from console with the same input works correctly?

Edit: notice after posting there's already this answer in the comments. Run vim in binary mode as vim -b asterix. I think the problem has something to do with conversions caused by encoding/...
avysk's user avatar
  • 196
3 votes
Accepted

Vim hex editor with xxd not working as intended

This will happen if you start editing the xxd-dumped version of the binary file, in which case Vim will assume a UTF-8 encoding (which you can confirm with :set fenc? returning fileencoding=utf-8). ...
filbranden's user avatar
  • 28.8k
2 votes
Accepted

hex mode crashes after saving file

As I started to explain in comments, the issue is described in :help edit-binary: 8. Editing binary files *edit-binary* Although Vim was made to edit text files, it is possible to ...
D. Ben Knoble's user avatar
  • 26.2k
1 vote
Accepted

How to enter linefeed in binary mode?

This is apparently by design. Internally, each line of the file is stored as a NUL-terminated string. The actual linefeeds from a file are not stored at all; they simply delimit the strings when a ...
Mark Reed's user avatar
  • 226
1 vote

Vim hex editor with xxd not working as intended

Here's what I have in my ~/.vimrc to allow quite comfortable and issue-free editing of binary files, which are narrowed down to *.bin and *.hex files in the vimcode below, but that can be adjusted as ...
dsimic's user avatar
  • 217
1 vote

How to list content of nested jars

.jar files are essentially zip files (you'll probably have noticed the " zip.vim version vxx banner at the top of the buffer). There are a few plugins which aim to help open nested zips, so you could ...
Rich Churcher's user avatar
1 vote

How to edit binary files with Vim?

This looks like a handy little vim plugin that does the job using a temporary file which it writes back and forth for you automatically. Some years ago I found a similar plugin which I adapted and ...
Tim's user avatar
  • 426

Only top scored, non community-wiki answers of a minimum length are eligible