Nvi - Enhancing comfort I

24 Dec 2023

Nvi is a bug-for-bug compatible replacement of the 4BSD version of the famous text editor. This series is about enhancing comfort, if you suddenly find yourself enjoying it.

As this is a series of articles, the first will be about creating a suitable configuration file. This will take your experience with the little companion to the next level. The configuration file is divided into three different sections. These are display, edit and function. Relevant options for improving the display are:

"display
set autoprint
set number
set report=1
set ruler
set showmatch
set showmode

The first option is only relevant for nex. This will automatically print the current line. The options number, ruler and showmode customize the display. Line numbers are always printed to the left of the editor screen. A row/column line including the current mode is also displayed at the bottom of the screen. When entering curved or round braces, the showmatch option will highlight the matching opening brace for a second. When copying or modifying lines, nvi will also note this in the bottom line. As the report option is set to one, any line changes or yanks will be reported.

"edit
set altwerase
set autoindent
set expandtab
set shiftwidth=2
set tabstop=2
set wraplen=79

When editing code you'd always enable the autoindent, expandtab, shiftwidth and tabstop options. These automatically indent new lines correctly, switch tabs to spaces (the number set by shiftwidth). When entering tabs on a new line, tabstop controls the number of spaces. The altwerase option extends the definition of the characters that make up a whole word. Control-W deletes a word, while in insert mode, but a more detailed review of the keybindings follows. Finally, wraplen limits the characters that can be entered on a line to 79. This produces code or configuration files that are earsier to read when the display dimensions are small (as in an ssh session).

"function
set cedit=:
set extended
set iclower

The cedit option is the character used to edit nvi's colon command line history. So when in command mode, you only need to type two colons to edit the history. The extended option uses extended regex, and iclower is responsible for case-insensitivity in regex searches, unless the search string contains an uppercase character.

Although a little limiting, the options offer a little bit more comfort if you need to edit files on a server where nvi is the only option available. Next up: Using existing keybindings.