繁体   English   中英

如何从 shell 命令行运行 vim 命令?

[英]How to run a vim command from the shell command-line?

关于在vim运行 shell 程序有许多计算器溢出问题。 是否有可能做相反的事情,即,

$ vim :BundleInstall

允许我将BundleInstall作为 shell 脚本的一部分运行,而不必打开vim并手动运行它?

请注意,现在语法已更改,该行应为(根据@sheharyar ):

vim +PluginInstall +qall

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

vim +BundleInstall +qall

除了我之外还有其他人在看吗! 注意:这在 vundle 的Github README中。

根据vim 手册页man 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 文档

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

更复杂的东西怎么样?

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

不确定这是否完全正确,但它对我有用。 谢谢@jvc26

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

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

vim --cmd BundleInstall

做你想做的事?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM