nvi Quick Reference

Essential commands for the nvi editor (vi clone).

Modes

ESC        return to command mode
i, a, o    enter insert mode
:          enter ex mode

Movement

h / l      move left / right
j / k      move down / up
w / b      next / previous word
0          beginning of line
^          first non-blank character
$          end of line
G          go to last line
:n or nG   go to line number n

Editing

x          delete character
dd         delete line
dw, d$     delete word / to end of line
u          undo (only 1 level in nvi)
.          repeat last command

Joining Lines

J          join the next line to the current one
2J         join two lines
:g/^\s*$/d delete all blank lines

# Example: Move line 3 to the end of line 2
:2         go to line 2
J          join line 3 into line 2

Backspace Limitations

Note: In nvi, the Backspace key works only within the same line in insert mode. It cannot delete across line boundaries. Use J in command mode to join lines instead.

Copy & Paste

yy         yank (copy) line
p / P      paste after / before
"ayy       yank into register 'a'
"ap        paste from register 'a'

Search & Replace

/pattern      search forward
?pattern      search backward
n / N         next / previous match
:%s/old/new/g replace all in file
:s/old/new/g  replace all on current line

Files & Buffers

:e file    open another file
:w         write (save) file
:q         quit
:q!        quit without saving
:wq        write and quit
ZZ         write and quit (same as :wq)

Configuration

:set nu           show line numbers
:set autoindent   enable auto-indent
:set ignorecase   case-insensitive search
:set list         show invisible chars

Help

:viusage      show vi command reference
:exusage      show ex command reference
:q            exit help view

Important Notes