Notes on the nvi text editor

Aside from Vim, I sometimes use nvi as an even lighter-weight text editor. Don’t underestimate it though, it comes with lots of functionality built-in.

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:

Key      Action
{Move cursor to before current paragraph
}Move cursor to after current paragraph
[[Move cursor to beginning of file
]]Move cursor to end of file
/ForeMove cursor to next occurrence of 'Fore'
?BackMove cursor to previous occurrence of 'Back'
nMove cursor to next match of previous search term
uUndo. Then press . for multiple undo
:42Move cursor to line 42
y4lYank (copy) the next 4 characters starting from the cursor
y4yYank (copy) 4 lines starting from the cursor
pPaste yanked contents after current line
PPaste 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"