什么是VIM的启动过程?

时间:2014-09-03 02:49:32

标签: vim vim-plugin

我一直在使用vim多年,我使用Vbundle来管理插件,我一直很好奇vim的启动过程(当.vimrc或autoload下的脚本,插件来源。)有什么想法吗? / p>

2 个答案:

答案 0 :(得分:2)

vim --startuptime vimlog

在vimlog中,它会告诉每个进程和插件的成本。

答案 1 :(得分:1)

Vim本身记录了初始化过程。如果输入:

:help

进入Vim,然后选择starting.txt,然后选择initialization,它会显示所遵循的流程。

这不适合胆小的人,这是我Debian安装中的相关内容:



At startup, Vim checks environment variables and files and sets values
accordingly.  Vim proceeds in this order:

1. Set the 'shell' and 'term' option        *SHELL* *COMSPEC* *TERM*
    The environment variable SHELL, if it exists, is used to set the
    'shell' option.  On MS-DOS and Win32, the COMSPEC variable is used
    if SHELL is not set.
    The environment variable TERM, if it exists, is used to set the 'term'
    option.  However, 'term' will change later when starting the GUI (step
    8 below).

2. Process the arguments
    The options and file names from the command that start Vim are
    inspected.  Buffers are created for all files (but not loaded yet).
    The |-V| argument can be used to display or log what happens next,
    useful for debugging the initializations.

3. Execute Ex commands, from environment variables and/or files
    An environment variable is read as one Ex command line, where multiple
    commands must be separated with '|' or "".
                                *vimrc* *exrc*
    A file that contains initialization commands is called a "vimrc" file.
    Each line in a vimrc file is executed as an Ex command line.  It is
    sometimes also referred to as "exrc" file.  They are the same type of
    file, but "exrc" is what Vi always used, "vimrc" is a Vim specific
    name.  Also see |vimrc-intro|.

    Recommended place for your personal initializations:
        Unix            $HOME/.vimrc
        OS/2            $HOME/.vimrc or $VIM/.vimrc (or _vimrc)
        MS-DOS and Win32    $HOME/_vimrc or $VIM/_vimrc
        Amiga           s:.vimrc or $VIM/.vimrc

    If Vim was started with "-u filename", the file "filename" is used.
    All following initializations until 4. are skipped.
    "vim -u NORC" can be used to skip these initializations without
    reading a file.  "vim -u NONE" also skips loading plugins.  |-u|

    If Vim was started in Ex mode with the "-s" argument, all following
    initializations until 4. are skipped.  Only the "-u" option is
    interpreted.
                            *evim.vim*
     a. If vim was started as |evim| or |eview| or with the |-y| argument,
    the script $VIMRUNTIME/evim.vim will be loaded.
                            *system-vimrc*
     b. For Unix, MS-DOS, MS-Windows, OS/2, VMS, Macintosh, RISC-OS and Amiga
    the system vimrc file is read for initializations.  The path of this
    file is shown with the ":version" command.  Mostly it's "$VIM/vimrc".
    Note that this file is ALWAYS read in 'compatible' mode, since the
    automatic resetting of 'compatible' is only done later.  Add a ":set
    nocp" command if you like.
    For the Macintosh the $VIMRUNTIME/macmap.vim is read.

      *VIMINIT* *.vimrc* *_vimrc* *EXINIT* *.exrc* *_exrc* *$MYVIMRC*
     c. Four places are searched for initializations.  The first that exists
    is used, the others are ignored.  The $MYVIMRC environment variable is
    set to the file that was first found, unless $MYVIMRC was already set
    and when using VIMINIT.
    -  The environment variable VIMINIT (see also |compatible-default|) (*)
       The value of $VIMINIT is used as an Ex command line.
    -  The user vimrc file(s):
            "$HOME/.vimrc"  (for Unix and OS/2) (*)
            "s:.vimrc"      (for Amiga) (*)
            "home:.vimrc"   (for Amiga) (*)
            "$VIM/.vimrc"   (for OS/2 and Amiga) (*)
            "$HOME/_vimrc"  (for MS-DOS and Win32) (*)
            "$VIM/_vimrc"   (for MS-DOS and Win32) (*)
        Note: For Unix, OS/2 and Amiga, when ".vimrc" does not exist,
        "_vimrc" is also tried, in case an MS-DOS compatible file
        system is used.  For MS-DOS and Win32 ".vimrc" is checked
        after "_vimrc", in case long file names are used.
        Note: For MS-DOS and Win32, "$HOME" is checked first.  If no
        "_vimrc" or ".vimrc" is found there, "$VIM" is tried.
        See |$VIM| for when $VIM is not set.
    -  The environment variable EXINIT.
       The value of $EXINIT is used as an Ex command line.
    -  The user exrc file(s).  Same as for the user vimrc file, but with
       "vimrc" replaced by "exrc".  But only one of ".exrc" and "_exrc" is
       used, depending on the system.  And without the (*)!

     d. If the 'exrc' option is on (which is not the default), the current
    directory is searched for three files.  The first that exists is used,
    the others are ignored.
    -  The file ".vimrc" (for Unix, Amiga and OS/2) (*)
            "_vimrc" (for MS-DOS and Win32) (*)
    -  The file "_vimrc" (for Unix, Amiga and OS/2) (*)
            ".vimrc" (for MS-DOS and Win32) (*)
    -  The file ".exrc"  (for Unix, Amiga and OS/2)
            "_exrc"  (for MS-DOS and Win32)

     (*) Using this file or environment variable will cause 'compatible' to
     be off by default.  See |compatible-default|.

4. Load the plugin scripts.                 *load-plugins*
    This does the same as the command:  
        :runtime! plugin/**/*.vim
    The result is that all directories in the 'runtimepath' option will be
    searched for the "plugin" sub-directory and all files ending in ".vim"
    will be sourced (in alphabetical order per directory), also in
    subdirectories.
    Loading plugins won't be done when:
    - The 'loadplugins' option was reset in a vimrc file.
    - The |--noplugin| command line argument is used.
    - The "-u NONE" command line argument is used |-u|.
    - When Vim was compiled without the |+eval| feature.
    Note that using "-c 'set noloadplugins'" doesn't work, because the
    commands from the command line have not been executed yet.  You can
    use "--cmd 'set noloadplugins'" |--cmd|.

5. Set 'shellpipe' and 'shellredir'
    The 'shellpipe' and 'shellredir' options are set according to the
    value of the 'shell' option, unless they have been set before.
    This means that Vim will figure out the values of 'shellpipe' and
    'shellredir' for you, unless you have set them yourself.

6. Set 'updatecount' to zero, if "-n" command argument used

7. Set binary options
    If the "-b" flag was given to Vim, the options for binary editing will
    be set now.  See |-b|.

8. Perform GUI initializations
    Only when starting "gvim", the GUI initializations will be done.  See
    |gui-init|.

9. Read the viminfo file
    If the 'viminfo' option is not empty, the viminfo file is read.  See
    |viminfo-file|.

10. Read the quickfix file
    If the "-q" flag was given to Vim, the quickfix file is read.  If this
    fails, Vim exits.

11. Open all windows
    When the |-o| flag was given, windows will be opened (but not
    displayed yet).
    When the |-p| flag was given, tab pages will be created (but not
    displayed yet).
    When switching screens, it happens now.  Redrawing starts.
    If the "-q" flag was given to Vim, the first error is jumped to.
    Buffers for all windows will be loaded.

12. Execute startup commands
    If a "-t" flag was given to Vim, the tag is jumped to.
    The commands given with the |-c| and |+cmd| arguments are executed.
    The starting flag is reset, has("vim_starting") will now return zero.
    If the 'insertmode' option is set, Insert mode is entered.
    The |VimEnter| autocommands are executed.