7.1. Customizing vi

You have seen that vi operates differently on various terminals. (For instance, on "dumb" terminals, vi inserts @ symbols in place of deleted lines; on intelligent terminals, vi redraws the screen with each edit.) On modern UNIX systems, vi gets operating instructions about your terminal type from the terminfo terminal database. (On older systems, vi uses the original termcap database.)[1]

[1] The location of these two databases varies from vendor to vendor. Try the commands man terminfo and man termcap to get more information about your specific system.

There are also a number of options that you can set from within vi that affect how it operates. For example, you can set a right margin that will cause vi to wrap lines automatically, so you don't need to hit RETURN.

You can change options from within vi by using the ex command :set. In addition, whenever vi is started up, it reads a file in your home directory called .exrc for further operating instructions. By placing :set commands in this file, you can modify the way vi acts whenever you use it.

You can also set up .exrc files in local directories to initialize various options that you want to use in different environments. For example, you might define one set of options for editing English text, but another set for editing source programs. The .exrc file in your home directory will be executed first, then the one in your current directory.

Finally, any commands stored in the shell variable ...

Get Learning the vi Editor, Sixth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.