TonicBoxOS · editor reference

vi - the built-in editor

A vim-lite modal editor. It draws a full-screen VT100 UI sized to your terminal (80×24 by default, and it follows live resizes), so it only runs inside the interactive terminal. The keys are vim's - modes, counts, motions, operators, registers, regex search and substitute, undo/redo, visual mode, dot-repeat, syntax highlighting. Everything documented here is implemented.

open vi [file] screen 80×24 modes normal / insert / visual / cmdline undo multi-level + redo
Survival kit
vi notes.txt
open a file (creates it if missing)
i
start typing (insert mode)
Esc
stop typing, back to normal mode
:w then Enter
save
:wq
save and quit
:q!
quit, throwing away changes

00Modes

You start in normal mode, where keys are commands, not text. Insert commands (i a o...) drop you into insert mode where keys are typed literally; Esc returns to normal. v/V enter visual mode to select a span, and : / ? open the command line at the bottom. The mode shows in the status bar.

Most normal-mode commands take a leading count: 5j moves down five lines, 3dd deletes three lines, 3x deletes three characters.

01Moving around

KeysMove to
h j k l / arrowsleft, down, up, right (space also moves right; arrows work in every mode, including insert)
w Wstart of next word (W = whitespace-delimited)
b Bstart of previous word
e Eend of word
0 ^ $first column, first non-blank, end of line
gg G {N}Gfirst line, last line, line N
H M Ltop, middle, bottom of the visible screen
f{c} t{c}forward to / till char c on this line
F{c} T{c}backward to / till char c on this line
; ,repeat / reverse the last f t F T
%jump to the matching () [] {}
Ctrl-F Ctrl-Bpage forward / back
Ctrl-D Ctrl-Uhalf page down / up

02Editing

Enter insert mode:

KeysAction
i ainsert before / after the cursor
I Ainsert at first non-blank / end of line
o Oopen a new line below / above
Rreplace mode (overtype until Esc)

Operators combine with any motion, a count, or themselves for linewise:

KeysAction
d{motion} dddelete over motion / whole line (e.g. dw, d$, 3dd)
c{motion} ccchange (delete, then insert); cw acts like ce
y{motion} yyyank (copy) into a register

Single-key edits:

KeysAction
x Xdelete char under / before cursor
r{c}replace the single char under cursor with c
s Ssubstitute char / whole line (then insert)
C Dchange / delete from cursor to end of line
Jjoin the next line onto this one
~toggle case of the char under cursor

03Registers, paste, undo, repeat

KeysAction
p Ppaste after / before (linewise or charwise, matching the yank)
"{a-z}prefix a yank/delete/paste to use named register a-z
uundo
Ctrl-Rredo
.repeat the last change (respects a new count)

Every delete/change/yank also fills the unnamed register, so a bare p pastes the last thing you cut. Example: "ayy yanks a line into register a, "ap pastes it back.

 Visual mode

v Vstart a charwise / linewise selection
{motion}extend the selection with any motion
d x c ydelete, change, or yank the selection
Esccancel the selection

05Ex command line (:)

CommandAction
:w :w {file}write to the current file (or a named one)
:q :q!quit - vi never warns about unsaved changes, so :q and :q! are equivalent
:wq :xwrite and quit
:{N}jump to line N
:s/pat/repl/substitute first match on the current line
:s/pat/repl/gsubstitute every match on the line
:%s/pat/repl/gsubstitute across the whole file
:{A},{B}s/.../gsubstitute within a line range
:{A},{B}ddelete a range of lines
:syntax on :syntax offtoggle syntax highlighting (:syn on / :syn off also work)

Ranges accept line numbers, . (current line), $ (last line), and % (whole file). In the replacement, & stands for the whole match and \{c} inserts a literal character.

Syntax highlighting is on by default. vi colors C (.c) and shell (.sh, or a #! line naming sh) files - keywords, strings, numbers, and comments. Toggle it with :syntax off / :syntax on.

06What it does not have

It is deliberately small. Notable gaps versus real vim: