vim:加载插件后启动命令

Jua*_*blo 3 vim vim-fugitive

使用vim,我可以在vim打开时启动一个命令,例如:打开vim并创建一个拆分

vim +sp
Run Code Online (Sandbox Code Playgroud)

我使用 vim-fugitive 插件,我使用的是

vim +Gstatus
Run Code Online (Sandbox Code Playgroud)

我得到

E492: No es una orden del editor: Gstatus
Run Code Online (Sandbox Code Playgroud)

也许是因为 vim 启动时没有加载逃犯 Gstatus

当我从终端启动 vim 时,如何在加载插件后执行命令?

特别是,如何从Gstatus预加载的终端启动 vim 。

ben*_*her 5

您的一般问题的答案包含在:help startup. 以下是一些相关部分:

3. Execute Ex commands, from environment variables and/or files
...
      *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 user vimrc file(s):
            "$HOME/.vimrc"  (for Unix and OS/2) (*)
...
            "$HOME/_vimrc"  (for MS-DOS and Win32) (*)
            "$VIM/_vimrc"   (for MS-DOS and Win32) (*)
...
4. Load the plugin scripts.                 *load-plugins*
    This does the same as the command: >
        :runtime! plugin/**/*.vim
...
8. Perform GUI initializations
    Only when starting "gvim", the GUI initializations will be done.  See
    |gui-init|.
...
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.
Run Code Online (Sandbox Code Playgroud)

这有点像作弊,不能在终端中与 vim 一起使用,但是您可以将命令放入 gvimrc 文件中,它们将在加载所有插件后运行。正如@Peter Rincker 在他回答后的评论中所建议的那样,更可靠的是使用VimEnter自动命令。

对于您的具体问题,fugitive 使用VimEnter在其插件文件中定义的自动命令来定义:Gstatus和其他命令。如果你想:Gstatus自动执行,你应该使用类似的自动命令并确保它在逃犯之后定义,这样你的将在逃犯之后执行。例如,将此行(未经测试)放入~/.vim/after/plugin/myfugitive.vim或诸如此类:

:au VimEnter * if exists(':Gstatus') | Gstatus | endif
Run Code Online (Sandbox Code Playgroud)

这将测试命令是否已定义;如果是这样,它将调用该命令。