Tested on OpenBSD 6.3 and 6.4

Edit text with vi(1)

On OpenBSD vi(1) is based on nvi 1.79, written by Keith Bostic.

You can’t record macros in nvi, but you still can use them. Add a sequence of commands into a buffer (for example, "q...), then apply the macro as usual (with @q).

To edit multiple files: vi file1 file2, then :n[ext], :prev to switch, and :ar[gs] to list them all.

To open one more file :e[dit] file, then ^6 to alternate between two, or use :e# command.

To open in a split :E[dit] file, then ^W to switch between windows, and to set the window height to 20 lines :res[ize] 20.

To scroll current line to the top z<Enter>, to the center z., and to the bottom of screen z-. Scroll lines with ^Y and ^E as usual.

To search for the “expression” and place the next occurence of it to the center of screen: /expression/z..

Undo and redo: Press u to undo previous edit, then press . (dot) to undo, to redo press u again.

Increment a number: place cursor at the first digit and press #.

To redraw the screen press ^L.

If you miss Visual mode, try marks. For example, mark the line by pressing mm, move to another line, then delete from the current to the marked line with d'm. Or copy to the buffer with y'm.

Break lines at column 72 in Insert and Append modes.

:set wraplen=72

Format a paragraph with goal line length 72, allow indented paragraphs.

:?^$?,//!fmt -pw 72

Sort lines in a paragraph (in Command mode):


To remove trailing spaces:


To edit command-history:

:set cedit=\

Where <TAB> is the actual tab character: press ^V, then <TAB>.

To read help:


If you need Unicode, use nvi2:

# pkg_add nvi
nvi-2.1.3p1-iconv: ok

See also

.exrc, .profile, .tmux.conf, Why vi Rocks, vi command help guide by Jeff W.