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

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