The nvi text editor
nvi is a programmer’s text editor that runs inside of a terminal emulator, like the macOS Terminal.app. It descends from an early text editor named vi, and can only be controlled with the keyboard. Most fans of vi use vim, another descendent, which has seen decades of feature development and includes an entire programming language for extending its functionality, with thousands of plugins available. nvi’s limitations compared to “modern” editors like vim can seem crippling:
-
There are no colors or font styling and no programming language syntax highlighting.
-
Text is not wrapped to the next line at word boundaries.
-
Aside from a few ways to run external commands (vi’s
!
and ex’s:!
or:read !
), there are no hooks to extend its functionality. -
The initialization file for user preferences (
~/.nexrc
) can only run interactive editor commands and is not written in a programming language with control flow or functions. -
The undo and redo history for a file is lost when the editor closes.
-
The only UI customization settings are
list
(show invisibles),ruler
(show cursor line number and column), andnumber
(show line numbers to the left of each line).
On the other hand, nvi does have some nice features:
-
It opens files extremely quickly.
-
Editing buffers can be opened in horizontal and vertical split windows, allowing multiple files to be compared or referenced in the same editing session.
-
It’s possible to record and replay ad-hoc “macros” for batch editing operations.
-
For C programmers, there’s cscope and ctags integration on par with vim. Function and structure definitions can be navigated using a stack to jump back to earlier definitions. If multiple definitions are available, nvi can cycle between them, too.
In 2019, I stopped using neovim and tried out macOS GUI applications as my main text editor, eventually settling on Sublime Text. For the few terminal-based editing tasks that remained, I switched to nvi, since it felt responsive and familiar, having used vim for years. It only took a few days to finish Configuring the defaults of nvi to my preferences.
When I switched from vim, some things took getting used to.
The undo command works differently under nvi: instead of typing u
multiple times to continue undoing changes, uu
will undo and then redo the change (the second u
undoes the first).
To undo multiple times, type the repeat last command .
after the first u
.
For some reason, it’s impossible to backspace delete text that is already present in the file before the current insert mode switch.
That text has to be changed or deleted in normal mode, once it’s been inserted.
Unfortunately, there is still some Missing nvi functionality that I haven’t been able to add, even with Modern nvi mappings.