Trying out the nvi editor



Having fun with FreeBSD on my Libretto this afternoon, I didn't have internet access to install Vim from ports so I decided to finally learn more about the bundled nvi editor. I missed syntax highlighting, but if you customise it right it's still a nice, lightweight, capable editor.

They’re similar, sort of, in some ways, kinda

Because Vim and nvi are both implementations of the classic vi/ex they have a number of functional similarities, but because nvi has been essentially static for licencing reasons in the BSDs and given Vim's continuous and rapid development, the gap between the two editors has been widening for quite some time. That was a needlessly long sentence.

Historians with complex flowcharts showing the origins of software would faint in horror at this assertion, but I like to think of nvi as a sort of "Vim-lite". In that context I don't fret about lost features, I just learn what they have in common and work with it, just like a guy with a scooter doesn't expect it to perform the same as his dad's Ducati. Does that make sense?

nvi, Vim

Configuration philes

Unlike Vim's ~/.vimrc, Nvi reads from the historically named ~/.nexrc file.

I like to include plenty of comments in my dotfiles, but as I learned from trial and error (and error, and error!) nvi is more picky about what you can include. You can't place comments on the same line as settings, and if you include a blank line anything below it is ignored!

This is part of my ~/.nexrc file, you can check out the full version on my dotfiles site if you're interested.

set columns=80
set secure
set autoindent
set shiftwidth=2
set tabstop=2
set ts=2
set errorbells
set flash
set verbose
set number
set ruler
abbr _aa This is The Tale, of Alan A'Dale
abbr _bw The Bird is The Word
abbr _gc Grilled cheese sandwiches
abbr _nc #include <ncurses.h>

Why not just install Vim Ruben? Gosh!

Even if the first thing you do on a fresh system is install Vim, nano or another editor, because nvi is distributed with all the major BSDs by default it's a great idea to have a working knowledge of it. It's like a dependable friend :).

Author bio and support


Ruben Schade is a technical writer and IaaS engineer in Sydney, Australia who refers to himself in the third person in bios. Wait, not BIOS… my brain should be EFI by now.

The site is powered by Hugo, FreeBSD, and OpenZFS on OrionVM, everyone’s favourite cloud infrastructure provider.

If you found this post helpful or entertaining, you can shout me a coffee or buy some silly merch. Thanks!