romanzolotarev.com: support me and follow on twitter

TIL #OpenBSD nvi can do split window... Thanks @romanzolotarev!"
ParadeGrotesque (@ParadeGrotesque)


Upgrade from Vim to vi(1)

Before switching to OpenBSD, I used Vim as the default text editor and used vi(1) on servers. Recently I decided to switch to vi(1) full time.

On OpenBSD vi(1) is actually nvi based on version 1.79, written by Keith Bostic.

Why did I switch to nvi?

What is missing?

For several Vim features, I couldn't find any workarounds and really miss them:

Insert-mode completion, text objects, viminfo (save command history, marks, registers), search for words under the cursor.

For some features, I managed to find workarounds.

For example, for rare cases when I need Unicode, I use nvi2:

# pkg_add nvi

Instead of syntax highlighting, I use cleaner formatting and linters, but I understand that this may not work for hipsters some software developers.

I've replaced some features with utilities and shell scripts:

Vim feature nvi workaround
sort /usr/bin/sort
spell checking /usr/bin/spell
diff mode /usr/bin/diff
text formatting (gqap) /usr/bin/fmt
extended search patterns /usr/bin/sed -E
vimgrep /usr/bin/grep
plugins /bin/sh
macros /bin/sh
automatic commands /bin/sh
scripts and expressions /bin/sh

nvi tricks

To edit multiple files: vi file1 file2, then :n[ext], :prev to switch, and :ar[gs] to list them all.

To open one more file :e[dit] file, then ^6 to alternate between two.

To open in a split :E[dit] file, then ^W to switch between windows, and to set the window height to 20 lines :res[ize] 20.

Undo and redo: Press u to undo previous edit, then press . (dot) to undo, to redo press u again.

Increment a number: place cursor at the first digit and press #.

To redraw the screen press ^L.

If you miss Visual mode, try marks. For example, mark the line by pressing mm, then move to the line you need, then delete from the current to the marked line with d'm.

Break lines at column 72 in Insert and Append modes.

:set wraplen=72

Format a paragraph with goal line length 72, allow indented paragraphs.

:?^$?,//!fmt -pw 72

Sort lines in a paragraph (in Command mode):

!}sort

To remove trailing spaces:

:%s/[[:space:]]\{1,\}/

To edit command-history:

:set cedit=^[

To read help:

:help

Tested on OpenBSD 6.3

See also

.exrc, .profile, .tmux.conf