hexpair : Advanced HEX Editor of Files of Any Size with No External Dependencies
| script karma |
Rating 2/2,
Downloaded by 3 |
Comments, bugs, improvements
|
Vim wiki
|
| created by |
| Michal Růžička |
| |
| script type |
| utility |
| |
| description |
Hexpair is not the best hex editor in the world, and it does not try to be.
What it is, is the hex editor that is always there – wherever you have your Vim. And you can switch into it in the middle of what you are doing: a file you already opened with a plain “vim file.md” turns into a hex editor with one command, and turns back with another. The cursor stays on the same byte across the switch, both ways.
When you know in advance that you want hex, “vimhex file.bin” opens it that way. And it makes no difference whether the file is 8 KiB or 8 TiB. Hexpair never loads the whole file: it works one page at a time (128 KiB by default), so editing an 8 TiB file costs the same ~20 MiB of memory as editing an 8 KiB one. You get the full feature set on a file of any size, on Linux, macOS and the BSDs, on native Windows and inside WSL.
Hexpair is written entirely in Vim script, with no external dependencies beyond the xxd utility – which ships with Vim itself (and PowerShell on Windows). No “sed”, no “tr”, no “dd”. You need no administrator rights on the target machine: unpack it into your own Vim package directory and you have a hex editor rather more capable than it first looks.
It is open-source avaialble on GitHub: https://github.com/michal-ruzicka/hexpair
# What It Does
* Cursor and selection highlighting is synchronised between the HEX and the ASCII column: put the cursor on a hex byte and the character lights up, and the other way round. The same for a Visual selection.
* Full editing. Not only changing the value of bytes that are there, but deleting bytes and inserting new ones anywhere in the file.
* Bytes you have changed and not yet written are highlighted, so an edit in a dump does not look like everything around it.
* Search the whole file, by text or by a hex string, with “?” standing for any single hex digit. Search and replace.
* Insert bytes from a string in a target encoding: type “Škola” and you get the UTF-8 bytes “c5 a0 6b 6f 6c 61”; type “++enc=cp1250 Škola” and you get the cp1250 bytes “8a 6b 6f 6c 61”.
* A hex diff mode that marks the bytes differing from another file, shows what that file holds at the cursor, jumps straight from change to change, and gives you two synchronised panes with “vimhexdiff”.
* A data inspector: what the bytes under the cursor mean as numbers – 8 to 64 bits, signed and unsigned, both endiannesses, both IEEE 754 floats – or as a UTF sequence, with the characters named.
* Fast movement anywhere in the file, by page or by byte offset, absolute or relative, plus named marks of your own. Jumps between your unwritten edits, between search matches, and between differences in diff mode.
* On Windows, optional “gvimhex” and “gvimhexdiff” entries in the Explorer right-click menu. |
| |
| install details |
Hexpair is open source and lives at
https://github.com/michal-ruzicka/hexpair
Reproducible, GPG-signed releases are ready to use at
https://github.com/michal-ruzicka/hexpair/releases
Hexpair is a plain Vim 8 package. No administrator rights are needed anywhere below.
It installs defensively: it maps no keys of its own, defines no shell functions and puts nothing on your PATH. All of that is one line away if you want it.
# Quick Install
## Linux, macOS, BSD, WSL
Unpack the release tarball into your own package directory and build the
help tags:
mkdir -p ~/.vim/pack/plugins/start
tar xf hexpair.vX.Y.Z.tar -C ~/.vim/pack/plugins/start/
vim -c 'helptags ALL' -c 'q'
Then ":help hexpair" has the whole manual.
## Optional: Key Mappings and Shell Commands
Hexpair defines no key mappings by default – it gives you commands and <Plug> targets, and which keys those go on is yours to decide. A ready-made set comes with it. One line in your .vimrc, after mapleader is set:
echo 'runtime pack/*/start/hexpair/hexpair.vimrc' >> ~/.vimrc
That line is right on every platform: 'runtimepath' already points at the per-user Vim directory, whatever it is called there.
The “vimhex”, “vimhexdiff”, “gvimhex” and “gvimhexdiff” shell functions are not defined until you ask for them either. In Bash:
echo 'source ~/.vim/pack/plugins/start/hexpair/hexpair.bashrc' >> ~/.bashrc
## Native Windows
Unpack the same tarball into your Vim package directory:
%USERPROFILE%\vimfiles\pack\plugins\start\
so that the plugin ends up in
%USERPROFILE%\vimfiles\pack\plugins\start\hexpair
For the “vimhex”, “vimhexdiff”, “gvimhex” and “gvimhexdiff” commands, put that directory on your user PATH. Open the environment variable editor with
rundll32 sysdm.cpl,EditEnvironmentVariables
and add it to Path under User variables. Do NOT use setx PATH “%PATH%;...”: %PATH% there is the system and the user paths already joined together, so it writes the whole lot into your user Path and truncates it at 1024 characters.
The key mappings work the same way as everywhere else – add
runtime pack/*/start/hexpair/hexpair.vimrc
to your %USERPROFILE%/_vimrc.
### Optional: Windows Explorer Context Menu
Two ready-made registry files ship with the plugin. For a default install there is nothing to edit in them – their paths are written against the package directory above. Add the “vimhex” submenu with
reg import "%USERPROFILE%\vimfiles\pack\plugins\start\hexpair\vimhex-contex-entry.add.reg"
and take it out again with
reg import "%USERPROFILE%\vimfiles\pack\plugins\start\hexpair\vimhex-contex-entry.remove.reg"
You can also just double-click either file.
## With a Plugin Manager
The repository is a plain Vim package, so every manager takes it as it
comes and builds the help tags itself:
" vim-plug
Plug 'michal-ruzicka/hexpair'
" minpac
call minpac#add('michal-ruzicka/hexpair')
# Requirements
Vim 8.0 or later – 8.0.0000 itself will do – and xxd. Newer Vims are used where they help: with Vim 9.0.0795 and +num64, searching and comparing read raw bytes instead of hex and run several times faster. Nothing is required that Vim does not already bring with it.
One platform note: on native Windows, xxd keeps its seek offset in a 32-bit C long, so past 2 GiB it would read and write the wrong place. Hexpair does the seeking with PowerShell beyond that point instead, and everything keeps working – reading, searching, comparing, overwriting, growing, shrinking. Only the cost changes. |
| |
script versions (upload new version)
Click on the package to download.
ip used for rating: 216.73.216.158
|