Notes on the nvi text editor

by Jochem Kossen

Aside from Vim, I sometimes use an even lighter text editor such as nvi. Don’t underestimate it though, it comes with more functionality built-in than you need most of the time.

A few tips on using nvi

nvi offers a lot of shortcuts for functionality to help you edit conveniently and fast. Here are a few I use regularly:

{       Move cursor to before current paragraph
}       Move cursor to after current paragraph
[[      Move cursor to beginning of file
]]      Move cursor to end of file
/Fore   Move cursor to next occurrence of ‘Fore’
?Back   Move cursor to previous occurrence of ‘Back’
n       Move cursor to next match of previous search term
u       Undo. Then press . for multiple undo
:42     Move cursor to line 42
y4l     Yank (copy) the next 4 characters starting from the cursor
y4y     Yank (copy) 4 lines starting from the cursor
p       Paste yanked contents after current line
P       Paste yanked contents before current line
.       Repeat last modification action (undo as well, so multiple undo!) 

Configuration

nvi uses a file called .nexrc in your home folder.

Here’s an example that I tend to use. Download the file and save it as .nexrc in your home folder. Then customize it to your heart’s desire! :-)

=> nexrc.txt

Contents:

" automatic indentation
set autoindent

" enable file name completion on <TAB>
set filec=\ 

" command editor / history opens on :<TAB>
set cedit=\ 

" incremental search
set searchincr

" press \dd in command mode to insert current date
map \dd :r !date +"\%Y-\%m-\%d \%a"

" press \dt in command mode to insert current date and time
map \dt :r !date +"\%Y-\%m-\%d \%a, \%H:\%M"

" press \dT in command mode to insert day of week, full date, time and offset
map \dT :r !date +"\%a, \%d \%b \%Y \%H:\%M:\%S \%z"