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 |
| /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:
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"