Notes on the nvi text editor

by Jochem Kossen on

english, tech

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:

 1" automatic indentation
 2set autoindent
 3
 4" enable file name completion on <TAB>
 5set filec=\	
 6
 7" command editor / history opens on :<TAB>
 8set cedit=\	
 9
10" incremental search
11set searchincr
12
13" press \dd in command mode to insert current date
14map \dd :r !date +"\%Y-\%m-\%d \%a"
15
16" press \dt in command mode to insert current date and time
17map \dt :r !date +"\%Y-\%m-\%d \%a, \%H:\%M"
18
19" press \dT in command mode to insert day of week, full date, time and offset
20map \dT :r !date +"\%a, \%d \%b \%Y \%H:\%M:\%S \%z"

Meta

Tags: linux, nvi, editor, console, lightweight

Permalink: https://jkossen.nl/nvi/