sponsor Vim development Vim logo Vim Book Ad

vim-deadc0de : Hex editor for Vim. It uses UNIX utility xxd for conversion.

 script karma  Rating 8/2, Downloaded by 308  Comments, bugs, improvements  Vim wiki

created by
Artem Korotchenko
 
script type
ftplugin
 
description
- Open hex editor by pressing <Shift-F6>. (Of course, you can set your own
  keybinding.) It does buffer conversion.
- When you complete editing, convert to plain text/blob back by pressing
  <Shift-F6>.
- Vim almost supports hex edition, but it lacks of very important features.
  This plugin updates ASCII block of edited blob while you're changing the
  HEXes.
- Reverse action is supported too. Edit the ASCII block and it changes the
  HEX.
  But be sure the edited ASCII line doesn't contain any unprintable
  characters, i. e. control sequences. Such characters are presented by
  dotas (.).
- The plugin highlights the currently selected byte in HEX block and the
  corresponding character in ASCII block.
- Reverse is done too.
- Switch between them by entering "gs". (Again, you can set your own
  keybinding.)
- Data protection prevents you from breaking a hex file.
  Assume you has entered "x" character, which is not hexadecimal character.
  Buffer would be restored immidiately.
- Data protection can be toggled by "gp". (Or another keybinding.)
- xxd utility supports only 7-bit ASCII table encoding that outputs in ASCII
  block. (Not all special characters work even so.).
  Extended encodings which use eight bit are not supported by xxd.
  But this plugin adds support of all printable characters. (One-byte encodings
  Latin 1, KOI8-R, CP1251, CP866 are tested; One-byte characters from UTF-8 are
  tested.)
- Work with newlines accurately.
  Please, set binary mode and turn off EOL if you are editing an blob.
- Open hexadecimal editor in a new buffer. (Due to safety.)
  It is saved to temporary directory, usually, /tmp/.
- Some options allow to tune the plugin. (Number of them will increase in
  future.)
 
install details
Install xxd.
Install Perl interpreter and Iconv binding for it:

$ sudo apt install xxd
$ sudo apt install perl libtext-iconv-perl

Copy the plugin to your Vim directory (usually, ~/.vim/):

+ doc/vim-deadc0de.txt
+ plugin/vim-deadc0de.vim
+ ftplugin/xxd.vim

Rebuild the Vim documentation:

:helptags ~/.vim/doc/

Then add to your .vimrc:

" General behavior
filetype on        " Enable file detection
filetype plugin on " Enable loading the plug-in files for specific file types
syntax on          " Enable syntax highlighting

" Load hex editor
runtime plugins/vim-deadc0de.vim

" <Shift-F6> Convert to hex / convert back using vim-deadc0de
noremap <S-F6> :HexConvert<CR>
imap    <S-F6> <C-O><S-F6>

" Toggle hex file protection by entering "gp".
" This protection is also controlled by g:deadc0de_protection.
map gp <Plug>hexprotectiontoggle

" Move cursor to the corresponding ASCII character (and then back) by entering
" "gs"
map gs <Plug>hexblockscycle

(You can use any other available keybindings for this purpose.)

vim-deadc0de is filetype plugin (ftplugin), not syntax plugin.
But it works in conjunction with xxd.vim syntax plugin by Charles E. Campbell.
xxd.vim should be already installed in your system, check it:

$ ls /usr/share/vim/vim*/syntax/xxd.vim # Debian- and Ubuntu-based distros path
 

rate this script Life Changing Helpful Unfulfilling 
script versions (upload new version)

Click on the package to download.

package script version date Vim version user release notes
vim-deadc0de.tar.xz 0.2.1 2023-05-17 8.2 Artem Korotchenko Increase performance (i. e. speed) of extended HEX-ASCII conversion by multiple thousands of times
vim-deadc0de.tar.xz 0.1.9 2023-05-13 8.2 Artem Korotchenko Plugin rename to vim-deadc0de
vim-hec5.tar.xz 0.1.7 2022-11-13 8.2 Artem Korotchenko - Data protection can be toggled by "gp". (Or another keybinding.)

Many bugs had been fixed.
vim-hec5.tar.xz 0.1.1 2022-11-07 8.2 Artem Korotchenko Blocks cycle mapping bug fix
vim-hec5.tar.xz 0.1.0 2022-11-07 8.2 Artem Korotchenko - Data protection prevents you from breaking a hex file.
  Assume you has entered "x" character, which is not hexadecimal character.
  Buffer would be restored immidiately.
- Some options allow to tune the plugin. (Number of them will increase in
  future.)

And other improvements and bug fixes.
vim-hec5.tar.xz 0.0.11 2022-11-03 8.2 Artem Korotchenko Initial upload
ip used for rating: 3.22.171.136

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to the maillist. Help Bram help Uganda.
   
Vim at Github