My .exrc (annotated)

Don’t crib configuration files from others - at least not without understanding every line and making a conscious decision to include it. You can crib from mine, because you are reading this page and therefore have an explanation of every line.

Note: You can find the history of my .exrc file in this public Git repository.

This is not for the “vim” editor. This is a .exrc file which I use with OpenBSD vi(1). It may work with other vi ports.

set autoindent

This lets me keep the current indentation level when creating a new line. Generally useful for programming. Ctrl-T will generally insert a tab character, because I’ve left those settings default; however, I have to deal with many different indentation levels in the real world. vi(1) will insert tabs wherever possible, but usually space-based indentation that I encounter uses 2 spaces, so this is rarely an issue.

Recommendation: Helpful for anything with an indented block structure.

set edcompatible

This setting has an odd name, but what it does is remember the c/g “confirm” and “global” options for the s (substitute) ex command. Without this option, to repeat :s/foo/bar/g, one would have to use &g explicitly, or else the result would be as :s/foo/bar.

Recommendation: Personal preference.

set leftright

Without this setting, vi(1) wraps lines longer than the screen visually; with it, they instead continue off the edge of the screen and the screen can be horizontally scrolled. It is not made obvious that a line continues off the edge of the screen; however, in practice, this is not generally hard to tell.

Recommendation: Personal preference.

set ruler

Displays the current row and column near the center of the bottom line of the screen. The status line goes away temporarily when typing an ex command or when a status message is displayed.

Recommendation: Very useful, and this line is not used for anything by default. Set this alongside showmode.

set searchincr

Makes searches (/ and ?) incremental - i.e., the editor jumps to the first occurrence of what has been typed so far as it is being typed.

Recommendation: Personal preference, but this is the behavior many are used to nowadays. I find this very helpful in correcting search typos quickly. However, it does not go back to your original position if you cancel the search.

set showmatch

Highlights the matching ( or { when a ) or } is typed.

Recommendation: Personal preference. I find this useful, but the jumping cursor may be distracting to others. The length of time the matching bracket is highlighted can be customized with matchtime.

set showmode

Displays the current mode (e.g., command, insert, append) at the right of the last line of the screen. The status line goes away temporarily when typing an ex command or when a status message is displayed.

Recommendation: Very useful, and this line is not used for anything by default. Set this alongside showmode.

set wraplen=72

Hard wraps at 72 columns. (To reflow existing text to within 72 columns, use e.g. !}fmt -72.) This is a very generally accepted text file width maximum, as archaic as its origins may be.

Recommendation: Weakly recommended; your use cases may vary from mine, but wrapping at 72 is a generally useful practice for everything from mail to code.