BVI(1)

๐Ÿ“ฆ
version 1.5.0 ยท 5 versions
, in alpine 3.24, fedora 43, fedora 44, nixos 26.05, nixpkgs unstable, ubuntu resolute, ubuntu stonking

๐Ÿ’– BVI โ€” the manual, but make it make sense ๐Ÿ’–

okay so bestie. sit down. we're talking about bvi and bview, and ngl this page is a whole vibe. it's BVI(1), User Commands, and it's giving "hex editor that actually loves you". let's get into it ๐Ÿซถ


โœจ NAME โœจ

bvi, bview โ€” visual editor for binary files. that's it, that's the whole pitch, slay ๐Ÿ’…

๐ŸŒธ VERSION ๐ŸŒธ

bvi-1.5.0 โ€” periodt, that's the version, don't @ me โœจ

๐Ÿฆ‹ SYNOPSIS ๐Ÿฆ‹

bvi   [-R] [-c cmd] [-f script] [-s skip] [-e end] [-n length] file...
bview [-R] [-c cmd] [-f script] [-s skip] [-e end] [-n length] file...

literally the same flags for both, they're twins, iconic ๐Ÿ‘‘

๐ŸŽ€ OPTIONS ๐ŸŽ€

okay so here's where it gets good. every single one of these matters, so pay attention bestie:

  • file... โ€” a list of filenames. the first one becomes the current file and gets read into the buffer, and the cursor parks itself on the first line of the buffer. wanna hop to the other files? use the :next command, easy ๐Ÿ’–
  • -R โ€” "Readonly". the readonly flag gets set for all the files, so you can't accidentally overwrite stuff with a write command. protective king behavior ๐Ÿ›ก๏ธ
  • -s skip โ€” makes bvi load a file not from the start but from offset skip. so it skips skip offset bytes from the beginning of the input. by default, offset is read as a decimal number. with a leading 0x or 0X it's hexadecimal, otherwise with a leading 0 it's octal. and if you append b, k, or m to offset, it gets interpreted as a multiple of 512, 1024, or 1048576 respectively. math girlies rise up ๐Ÿงš
  • -e end โ€” makes bvi load a file not till end but till address end. yeah. exactly what it says ๐ŸŒธ
  • -n length โ€” makes bvi not load the complete file but only length bytes. lil snack instead of the whole meal ๐Ÿ“
  • -c cmd โ€” cmd gets executed after the first file has been read. if cmd contains spaces it must be wrapped in double quotes (this depends on the shell you're using, iykyk). so like, quote it. please. ๐Ÿ™ˆ
  • -f script โ€” this one is a whole moment. it gives you a way to collect a series of ex (colon) commands into a script file, then use that file to edit other files. and since there is no binary stream editor "bsed", you can use this option to make several global changes in a binary file. no bsed? no problem, we improvise ๐Ÿ’…

๐Ÿ’œ DESCRIPTION ๐Ÿ’œ

Bvi stands for "Binary VIsual editor". yes. it's a screen oriented editor for binary files, and its command set is based on that of the vi(1) text editor. but here's the plot twist โ€” since bvi is a binary editor, it does not have the concept of "lines". all end-of-lines (EOLs) are simply bytes. therefore bvi's commands are different from vi's commands for all the line-oriented commands (see below). no lines, no drama, just bytes ๐Ÿ’€

๐Ÿ”ฅ COMPARISON ๐Ÿ”ฅ

the main differences between Vi and Bvi are, bestie:

the screen is divided into three sections (or panes): the byte offset (extreme left), the hex pane (middle), and an ascii pane (right) which shows as printable characters those bytes that are in the hex pane. on an 80 column terminal there will be sixteen hex values and their ASCII values on each screen line. and note that (as one would expect) the first byte has the offset '0' (zero). zero. not one. we start at zero here ๐Ÿซถ

you can toggle between the hex and ascii windows with the tab key (TAB). and toggling between these two windows does not change the current position (offset) within the file. your place is safe, periodt โœจ

No "lines" concept: files are treated as one long stream of bytes. the characters "newline" and "carriage return" are not special, id est they never mark the end of lines. therefore the lines on the screen do not represent lines in the usual way. data is broken across screen lines arbitrarily. as a consequence there are no commands in bvi from ex or vi that are based on line numbers, eg dd, yy, C, S, o, O. this also changes the meaning of "range" before the :write command to a byte offset, ie the command :100,200w foo writes all bytes (not lines) from offset 100 to offset 200 to the file foo. read that again. bytes. not lines. ๐Ÿ˜ญ

No "text objects": there are also no text-specific arrangements like words, paragraphs, sentences, sections and so on. gone. not here. we don't do that ๐ŸŒˆ

Extended "ruler": the bottom line of the screen shows the current address (byte offset) and the current character in these notations:

octal, hexadecimal, decimal and ascii.

Search patterns: all search commands understand these special characters:

.    any character
[]   set of characters
*    zero or more occurrences of previous char or set

but as there is no concept of lines you cannot use the standard symbols ("anchors") for "begin-of-line" (^) and "end-of-line" ($). searching for the start/end of lines must be done explicitly by adding these special characters to your search pattern using these meta sequences:

\n   newline
\r   return
\t   tab
\0   binary zero

Additional search commands: similar to the text search commands there are additional hex-search functions \ and # which allow one to search for any byte value. example: "\62 76 69" will search for the string "bvi". spaces between hex value are optional, so searching for "6775636B6573" will find "guckes". obsessed with this ngl ๐Ÿ”

changing the length of data (insertion, deletion) moves the data to other addresses. this is bad for many cases (eg. databases, program files) and is thus disabled by default. you can enable this commands by typing:
:set memmove

okay so now the BVI Modes, and there's three of them, main character energy for real:

๐Ÿ‘‘ Command Mode (Normal Mode) ๐Ÿ‘‘

input is treated as command. note that command mode is the default mode after startup and after escaping from input mode. use ESC (escape) to cancel a partial (uncompleted) command. unfinished business? cancel it, queen ๐Ÿ’…

๐ŸŒธ Input Mode ๐ŸŒธ

input is treated as replacement of current characters or (after the end of the file) is appended to the current file. this mode is entered from command mode by typing one of i, I, A, r, or R. you can enter the characters from the keyboard (in the ASCII window) or hexadecimal values (in the HEX window). type TAB to switch between these two windows. type ESC to finish the current input and return to command mode. type CTRL-C to cancel current command abnormally. know your exits bestie ๐Ÿšช

๐Ÿฆ‹ Command line mode (Last Line Mode or : mode) ๐Ÿฆ‹

similar to vi, this mode is entered by typing one of the characters : / ? \ # ! โ€” the command is terminated and executed by typing a carriage return; to cancel a partially typed command, type ESC to cancel the current command and return to command mode. so many ways in, one clean way out โœจ

๐ŸŒฟ ENVIRONMENT ๐ŸŒฟ

the editor recognizes the environment variable BVIINIT as a command (or list of commands) to run when it starts up. if this variable is undefined, the editor checks for startup commands in the file ~/.bvirc, which you must own. however, if there is a .bvirc owned by you in the current directory, the editor takes its startup commands from this file โ€” overriding both the file in your home directory and the environment variable. current directory wins, home dir and env var cry about it, that's just the rules ๐Ÿ†

๐Ÿ’ซ TERMINOLOGY ๐Ÿ’ซ

character names are abbreviated as follows:

  • CR โ€” 010 โ€” carriage return
  • ^A โ€” 001 โ€” control-a
  • ^H โ€” 008 โ€” control-h
  • ^I โ€” 009 โ€” control-i โ€” aka TAB
  • ^U โ€” 021 โ€” control-u
  • ^Z โ€” 026 โ€” control-z
  • ESC โ€” 027 โ€” escape โ€” aka ESC
  • DEL โ€” 127 โ€” delete
  • LEFT โ€” --- โ€” left arrow
  • RIGHT โ€” --- โ€” right arrow
  • DOWN โ€” --- โ€” down arrow
  • UP โ€” --- โ€” up arrow

and that's where part 1 leaves us, bestie โ€” more is coming, don't go anywhere ๐Ÿ’–

๐Ÿ’… COMMAND SUMMARY ๐Ÿ’…

okay bestie, before we dive in โ€” peek at TERMINOLOGY for the rundown on all the key-name abbreviations used in the command descriptions below. iykyk ๐Ÿซถ

๐ŸŒธ Abstract ๐ŸŒธ

Arrow keys move the cursor on the screen within the current window. that's it. that's the whole vibe.

โญ Sample commands โญ

:version    show version info
<- v ^ ->   arrow keys move the cursor
h j k l     same as arrow keys
u           undo previous change
ZZ          exit bvi, saving changes
:q!         quit, discarding changes
/text       search for text
^U ^D       scroll up or down

๐Ÿ”ข Counts before bvi commands ๐Ÿ”ข

Numbers may be typed as a prefix to some commands. They are interpreted in one of these ways, and which way depends on the command:

screen column       โŽช
byte of file        G
scroll amount       ^D  ^U
repeat effect       most of the rest

๐Ÿ›‘ Interrupting, canceling ๐Ÿ›‘

  • ESC โ€” end insert or incomplete command
  • DEL โ€” (delete or rubout) interrupts

๐Ÿ“ File manipulation ๐Ÿ“

  • ZZ โ€” if file modified, write and exit; otherwise, exit
  • :w โ€” write changed buffer to file
  • :w! โ€” write changed buffer to file, overriding read-only (this is a "forced" write, no cap ๐Ÿ’…)
  • :q โ€” quit when no changes have been made
  • :q! โ€” quit and discard all changes
  • :e file โ€” edit file
  • :e! โ€” re-read current file, discard all changes
  • :e # โ€” edit the alternate file
  • :e! # โ€” edit the alternate file, discard changes
  • :w file โ€” write current buffer to file
  • :w! file โ€” write current buffer to file overriding read-only (this "overwrites" the file)
  • :sh โ€” run the command as set with option "shell", then return
  • :!cmd โ€” run the command cmd from "shell", then return
  • :n โ€” edit next file in the argument list
  • :f โ€” show current filename, modified flag, current byte offset, and percentage of current position within buffer
  • ^G โ€” same as :f

โœ๏ธ Additional edit commands โœ๏ธ

You can insert/append/change bytes in ASCII/binary/decimal/hexadecimal or octal representation. You can enter several (screen) lines of input. A line with only a period (.) in it will terminate the command.

๐Ÿšจ You must not type in values greater than a byte value. That causes an abandonment of the command. bye bye input, we hardly knew ye ๐Ÿ˜ญ

Pressing the CR key does not insert a newline-character into the file. If you use ASCII mode you can use the special characters \n, \r, \t and \0.

:i aCR      insert bytes (ASCII) at cursor position
:a bCR      append bytes (Binary) at end of file
:c hCR      change bytes (hexadecimal) at cursor position

๐Ÿงฎ Bit-level operations ๐Ÿงฎ

  • :and n โ€” bitwise 'and' operation with value n
  • :or n โ€” bitwise 'or' operation with value n
  • :xor n โ€” bitwise 'xor' operation with value n
  • :neg โ€” two's complement
  • :not โ€” logical negation
  • :sl i โ€” shift each byte i bits to the left
  • :sr i โ€” shift each byte i bits to the right
  • :rl i โ€” rotate each byte i bits to the left
  • :rr i โ€” rotate each byte i bits to the right

๐Ÿ“ Command mode addresses ๐Ÿ“

:w foo         write current buffer to a file
               named "foo"
:5,10w foo     copy byte 5 through 100 into as
               file named foo
:.,.+20w foo   copy the current byte and the next
               20 bytes to foo
:^,'aw foo     write all bytes from the beginning
               through marker 'a'
:/pat/,$ foo   search pattern pat and and copy
               through end of file

๐Ÿงญ Positioning within file ๐Ÿงญ

  • ^B โ€” backward screen
  • ^F โ€” forward screen
  • ^D โ€” scroll down half screen
  • ^U โ€” scroll up half screen
  • nG โ€” go to the specified character (end default), where n is a decimal address
  • /pat โ€” next line matching pat
  • ?pat โ€” previous line matching pat
  • \hex โ€” jump to next occurrence of hex string hex
  • #hex โ€” jump to previous occurrence of hex string hex
  • n โ€” repeat last search command
  • N โ€” repeat last search command, but in opposite direction

๐Ÿ–ฅ๏ธ Adjusting the screen ๐Ÿ–ฅ๏ธ

  • ^L โ€” clear and redraw screen
  • zCR โ€” redraw screen with current line at top of screen
  • z- โ€” redraw screen with current line at bottom of screen
  • z. โ€” redraw screen with current line at center of screen
  • /pat/z- โ€” search for pattern pat and then move currents line to bottom
  • ^E โ€” scroll screen down 1 line
  • ^Y โ€” scroll screen up 1 line

๐ŸŽ€ Marking and returning ๐ŸŽ€

  • mx โ€” mark current position with lower-case letter x. Note: this command works for all lower-case letters
  • 'x โ€” move cursor to mark x in ASCII section
  • `x โ€” move cursor to mark x in HEX section
  • '' โ€” move cursor to previous context in ASCII section
  • `` โ€” move cursor to previous context in HEX section

โฌ†๏ธโฌ‡๏ธ Line positioning โฌ†๏ธโฌ‡๏ธ

  • H โ€” jump to first line on screen ("top")
  • L โ€” jump to last line on screen ("low")
  • M โ€” jump to middle line on screen ("middle")
  • - โ€” jump onto previous line on screen
  • + โ€” jump onto next line on screen
  • CR โ€” same as +
  • DOWN or j โ€” next line, same column
  • UP or k โ€” previous line, same column

๐Ÿ”ค Character positioning ๐Ÿ”ค

  • ^ โ€” first byte in HEX window
  • $ โ€” end of screen line
  • l or RIGHT โ€” jump onto next byte (within current screen line)
  • h or LEFT โ€” jump onto previous byte (within current screen line)
  • ^H โ€” same as LEFT
  • space โ€” same as RIGHT
  • fx โ€” find next occurrence of character x
  • Fx โ€” find previous occurrence of character x
  • nโŽช โ€” jump onto nth byte/character within current line

๐Ÿงต Strings ๐Ÿงต

(works similar to the strings(1) command)

Note: "Words" are defined as strings of "nonprinting characters". slay ๐ŸŒˆ
  • e โ€” jump to next end of word
  • w โ€” jump to next begin of word
  • b โ€” jump to previous begin of word
  • W โ€” forward to next string delimited with a \0 or \n
  • B โ€” back to previous string delimited with a nonprinting char

๐Ÿ™ˆ Corrections during insert ๐Ÿ™ˆ

  • ^H โ€” erase last character (backspace)
  • erase โ€” your erase character, same as ^H (backspace)
  • ESC โ€” ends insertion, back to command mode

๐Ÿฆ‹ Append and replace ๐Ÿฆ‹

  • A โ€” append at end of file
  • rx โ€” replace current byte with char 'x'
  • R โ€” enter replace mode; for all subsequent input, the current byte is overwritten with the next input character; leave replace mode with ESC.

๐ŸŽฒ Miscellaneous Operations ๐ŸŽฒ

  • TAB โ€” toggle between ASCII and HEX section

๐Ÿ“ Yank and Put ๐Ÿ“

  • 3ySPACE โ€” yank 3 characters
  • p โ€” insert contents of yank buffer
  • o โ€” replace text with content of yank buffer
  • P โ€” put back at end of file

โ†ฉ๏ธ Undo, Redo โ†ฉ๏ธ

  • u โ€” undo last change
Note: Only the last change can be undone. Therefore this commands toggles between the last and second-t-last state of the buffer. so it's a lil toggle situation, not a full time machine ๐Ÿ˜ญ

โš™๏ธ Setting Options โš™๏ธ

With the :set command you can set options in bvi ๐Ÿ’–

  • autowrite (default: noaw) โ€” Save current file, if modified, if you give a :n, :r or ! command
  • columns (default: cm=16) โ€” on an 80 character wide terminal
  • ignorecase (default: noic) โ€” Ignores letter case in searching
  • magic (default: nomagic) โ€” Makes . [ * special in patterns
  • memmove (default: nomm) โ€” enables insert and delete commands
  • offset (default: of=0) โ€” adds an offset to the displayed addresses
  • readonly (default: noro) โ€” If set, write fails unless you use ! after command
  • reverse (default: nore) โ€” display otherwise-printable characters with their high bit set as reverse video
  • scroll (default: sc=1/2 window) โ€” Number of lines scrolled by ^U and ^D
  • showmode (default: mo) โ€” Displays statusline on bottom of the screen
  • terse (default: noterse) โ€” Let you obtain shorter error messages
  • window (default: window=screensize) โ€” Lines in window, can be reduced at slow terminals
  • wordlength (default: wl=4) โ€” Length of an ASCII-string found by w, W, b or B
  • wrapscan (default: ws) โ€” Searches wrap around past the end of the file
  • unixstyle (default: nous) โ€” The representation of ascii characters below 32 is displayed in the statusline as shown in ascii(7) if unset rather in DOS-style (^A)

๐Ÿ‘‘ AUTHOR ๐Ÿ‘‘

bvi was developed by Gerhard Buergmann, Vienna, Austria โ€” gerhard@puon.at

the literal icon who made all this happen ๐Ÿ’œ

๐ŸŒ WWW ๐ŸŒ

๐Ÿ“‚ FILES ๐Ÿ“‚

 $HOME/.bvirc          editor startup file
 ./.bvirc              editor startup file

๐Ÿ”— SEE ALSO ๐Ÿ”—

bmore(1), vi(1), strings(1), ascii(5)


okay bestie that's the whole page ๐Ÿ’– this lil masterpiece is BVI Version 1.5.0 from the 3rd Berkeley Distribution, and it's filed under BVI(1) ๐ŸŽ€ go forth and edit those bytes, you absolute main character ๐Ÿซถโœจ

๐Ÿ“ฆ where this page comes from