->Title Page
->Intro
->Unix
->Vi editor
-->Basics
-->Vi reference
--->Move commands
--->Search
--->Undo
--->Insert
--->Delete
--->Changing text
--->Substitution
--->Yanking
--->Insert mode
--->Display commands
--->Files
--->Macros
--->Shell commands
->Vi Startup
--->Important options
-->Miscellaneous tips
->Mirror sites
->Further reading

[ Up ]
[Prev][Home][Next]
[Author]

Vi ---> Vi startup

As discussed earlier vi is started by simply typing vi filename where the filename is optional. It is possible to include a list of filenames instead of just the one. This tells vi to edit the first file. After you are finished with the file it edits the second and continues this process until all the files in the list have been edited.

The editor can be initialized by the shell variable EXINIT, which looks like:


            EXINIT='<cmd>|<cmd>|...'
            <cmd>: set options
                   map ...
                   ab ...
            export EXINIT (in the Bourne shell)
However, a better way is to put the list of initializations into a file. If this file is located in your home directory, and is named .exrc and the variable EXINIT is not set, the list will be executed automatically at startup time. However, vi will always execute the contents of a .exrc in the current directory, if you own the file. Otherwise you have to type


            :so file
to source the file yourself.

In a .exrc file a comment is introduced with a double quote character: the rest of the line is ignored.1

On-line initializations can be given with vi +<cmd> file, e.g.:


    vi +x file              | The cursor will immediately jump to line x
                            |   (default last line).
    vi +/<string> file      | Jump to the first occurrence of <string>.
You can start at a particular tag with:


    vi -t <tag>             | Start in the right file in the right place.
Sometimes, e.g. if the system crashed while you were editing, it is possible to recover files lost in the editor by typing vi -r file. Typing vi -r shows the files you can recover. The readonly flag allows you to view a file with vi without the danger of accidentally saving changes. However, if you do make changes that you decide you want to save, typing :w! will override the readonly option.

Please notify owners of webpages with outdated links to these pages

1 An exception to this is if the last command on the line is a map[!] or ab command or a shell escape, a trailing comment is not recognized, but considered part of the command.
This section is based on "Vi Reference" by Maarten Litmaath et al.

Find this site useful? Want to give something back?

© 1993-2001 Christopher C. Taylor