2012-10-11 304 views
42

从vim运行shell程序有很多SO问题。我想知道是如果有可能做相反 - 即从命令行运行vim命令

$ vim :BundleInstall 

例如,让我跑BundleInstall为脚本的一部分,而不是打开的Vim并在第一手动运行运行?这可能吗?

回答

73

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

vim +PluginInstall +qall 

对于后人,此前,正确的路线是:

vim +BundleInstall +qall 

如若其他任何人比我看起来好!注意:这是在Github README vundle。

+0

这是直接从vundle README这里:https://github.com/gmarik/vundle – Conner

+1

呀 - 发现,获取手册页 – jvc26

+0

令人惊讶的是有见地的基础上,这个工作之后。我喜欢我们甚至不需要'man vim',并且感谢SO,向下滚动两页。 – peth

0

是否

vim --cmd BundleInstall 

你想要做什么?

+0

你需要加载的插件后,执行命令。使用'-c'选项 – kev

20

我认为这是你所需要的:

您应该检查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. 

或:

--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. 

这真的取决于你想要做什么。此外,由于在vundle自述文件中所述,如果您启动vim的是这样的:

vim +BundleInstall +qall 

这将安装无需打开vim的所有束选项。 而只是澄清,从vim documentation

: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. 

希望它能帮助!

2

我会为正在寻找更一般解决方案的人添加另一个答案。

vim +command可以运行一个Vim命令,但是可以从一个shell运行几个Vim命令。相反,在Ex模式下启动Vim并使用Here文档提供命令。这是我写的脚本的一个例子。它在文件中搜索一个模式并在其之前插入一些文本。

ex --noplugin +1 "$v_file" <<-END 
      set maxmempattern=8000 
      /^\s*\<endmodule\>/i 

      FIXME \`ifdef XXX_INCLUDE_API 
       \`include "${api_file}" 
      \`endif 

      . 
      w 
      q 
    END 
2

如何更复杂一些?

vim "+set ff=unix" "+wq" node_modules/less-monitor/bin/less-monitor 

不知道这是否完全正确,但它适用于我。 感谢@ jvc26

+0

我不明白这是一个新的问题(应该再单独询问),或一个新的答案。 –

+0

这只是一个例子,如何使用多字命令的解决方案,比如'+ set ff = unix'和'+ wq'而不是'+ qall'。在我的情况下,我需要更新文件。我张贴这为答案,只是因为我不能发表评论(50+声誉需要) – graceman9

+0

*癌症治愈*感谢... –