home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam  


Book HomeLearning the vi EditorSearch this book

11.4. Initialization

This section describes vim's initialization steps, including those taken for the GUI versions of vim.

11.4.1. Initialization for All vim Invocations

vim performs the following initialization steps:

  1. Set the shell and term options from the SHELL and TERM environment variables, respectively. On MS-DOS and Win32, use COMSPEC to set shell if SHELL is not set.

  2. If -u was supplied, execute the given file, and skip the rest of the startup file based initializations. The -s option has the same effect for ex mode; only the -u option will be interpreted. Use of -u NONE causes vim to skip all further initializations.

  3. Execute the system-wide vimrc file. The exact path is set when vim is compiled. A typical value is /usr/local/share/vim/vimrc.

  4. Execute instructions in the first place that exists of the following four:

  5. If the exrc option has been set, then vim looks in the current directory for the first file that exists of the following four. The others are ignored.

    • .vimrc

    • _vimrc

    • .exrc

    • _exrc

    On MS-DOS and Win32 systems, the _xxxrc files are looked for before the .xxxrc files.

  6. If they have not yet been set, the shellpipe and shellredir options are initialized based on the value of the shell option. The shellredir option is discussed in Section 11.9.1.

  7. If -n was given on the command line, updatecount is set to zero. (This option controls how often the swap file is updated. The more often, the more the swap file is synchronized with all your changes, but possibly with decreased performance. Zero means never.)

  8. If -b was supplied, set the appropriate options for editing binary files.

  9. Perform GUI initializations. See the next subsection.

  10. If viminfo is set, read the file indicated there.

  11. If -q was supplied, read the named quick fix file. The quick fix facility is described in Section 11.9.1.

  12. Open and fill all windows, as per the -o option. If -q was supplied, go to the first error.

  13. Jump to the tag given by the -t option, if supplied. Execute any commands given with -c.

That's a lot of steps. As in other areas, vim's extra facilities also provide extra flexibility and customizability.

As for nvi, you can place common initialization actions into your .exrc file (i.e., options and commands for UNIX vi and/or the other clones), and have your .vimrc file execute :source .exrc before or after the vim-specific initializations.

The viminfo file is much like the elvis session file. It can be used to save a large part of the state of your editing session in between logins. The viminfo file stores the following items:

  • The command-line history

  • The search string history

  • Contents of registers

  • File marks, pointing to locations in files

  • Last search/substitute pattern (for n and &)

vim reads this file at startup, and when exiting, merges its current state with the contents of the file and then rewrites it.



Library Navigation Links

Copyright © 2003 O'Reilly & Associates. All rights reserved.