从命令行运行vim命令

jvc*_*c26 50 vim bash shell zsh

关于从vim运行shell程序有很多SO问题.我想知道的是,是否有可能反过来 - 即

$ vim :BundleInstall
Run Code Online (Sandbox Code Playgroud)

例如,允许我作为脚本的一部分运行BundleInstall,而不是必须打开Vim并在首次运行时手动运行它?这可能吗?

jvc*_*c26 87

注意,现在语法已经改变,行应该读取(按照@sheharyar):

vim +PluginInstall +qall
Run Code Online (Sandbox Code Playgroud)

对于后代,以前,正确的路线是:

vim +BundleInstall +qall
Run Code Online (Sandbox Code Playgroud)

除了我以外的任何人都应该看!注意:这是在Github README for vundle中.

  • **如果**你需要传递参数:`echo'{"foo":"bar","baz":{"baa":0,"bao":1}}'| vim"+ setf json"-` (2认同)
  • 执行多个命令,例如 vim-plug: `vim +PlugInstall +PlugClean! +qall` (2认同)

Dan*_*chi 24

我认为这就是你需要的:

你应该查看vim 手册页:

-c {command}
    {command}  will  be  executed after the first file has been
    read.  {command} is interpreted as an Ex command.   If  the
    {command}  contains  spaces  it  must be enclosed in double
    quotes (this depends on the shell that is used).   Example:
    Vim "+set si" main.c
    Note: You can use up to 10 "+" or "-c" commands.
Run Code Online (Sandbox Code Playgroud)

要么:

--cmd {command}
    Like using "-c", but the command is  executed  just  before
    processing  any  vimrc file.  You can use up to 10 of these
    commands, independently from "-c" commands.
Run Code Online (Sandbox Code Playgroud)

这真的取决于你想做什么.另外,如vundle自述文件中所述,如果你像这样启动vim:

    vim +BundleInstall +qall
Run Code Online (Sandbox Code Playgroud)

这将安装所有捆绑选项而无需打开vim.只是为了澄清,从vim文档:

:qall

    This stands for "quit all".  If any of the windows contain changes, Vim will
    not exit.  The cursor will automatically be positioned in a window with
    changes.  You can then either use ":write" to save the changes, or ":quit!" to
    throw them away.
Run Code Online (Sandbox Code Playgroud)

希望能帮助到你!