Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

vim: launch command after load plugins

with vim, I can launch a command when vim is open, example: open vim and create a split

vim +sp

I use vim-fugitive plugin, is I use

vim +Gstatus

I get

E492: No es una orden del editor: Gstatus

maybe because fugitive not are loaded when vim launch Gstatus

when I launch the vim from terminal, how I can execute a command after the load of plugins ?

In particular, How I can launch vim from terminal with Gstatus preloaded.

like image 376
JuanPablo Avatar asked Aug 09 '26 01:08

JuanPablo


1 Answers

The answer your general question is contained in :help startup. Here are some relevant parts:

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.

It is sort of a cheat, and will not work with vim in a terminal, but you can put commands in your gvimrc file and they will be run after all the plugins are loaded. More reliable, as @Peter Rincker suggested in the comments after his answer, is to use a VimEnter autocommand.

For your specific question, fugitive uses a VimEnter autocommand, defined in its plugin file, to define :Gstatus and other commands. If you want to do :Gstatus automatically, you should use a similar autocommand and make sure it is defined after fugitive's, so that yours will be executed after fugitive's. For example, put this line (untested) in ~/.vim/after/plugin/myfugitive.vim or some such:

:au VimEnter * if exists(':Gstatus') | Gstatus | endif

That will test whether the command has been defined; if so, it will invoke the command.

like image 51
benjifisher Avatar answered Aug 11 '26 11:08

benjifisher



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!