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

dhxwm5r4  于 2023-01-30  发布在  Shell
关注(0)|答案(5)|浏览(204)

vim中运行shell程序会遇到很多堆栈溢出问题,是否可以反过来做,即

$ vim :BundleInstall

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

zu0ti5jz

zu0ti5jz1#

注意,现在语法已经更改,该行应该为(As per @sheharyar):

vim +PluginInstall +qall

对后代来说,以前正确的台词是:

vim +BundleInstall +qall

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

bmp9r5qi

bmp9r5qi2#

根据vim man pageman vim):

+{command}

-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的情况下安装所有bundle选项。为了说明起见,请参阅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.
polhcujo

polhcujo3#

再复杂点的怎么样?

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

不知道这是否完全正确,但它对我很有效。谢谢@jvc26

at0kjp5o

at0kjp5o4#

我将为那些正在寻找更通用的解决方案的人添加另一个答案。
vim +command可以运行一个Vim命令,但也可以从shell运行多个Vim命令。相反,可以在Ex-mode下启动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
e4yzc0pl

e4yzc0pl5#

是否

vim --cmd BundleInstall

做你想做的事

相关问题