linux中的vi怎么运行命令,linux – 如何通过shell脚本执行vim命令

备择方案

除非你真的需要特殊的Vim功能,否则最好使用非交互式工具,如sed,awk或Perl / Python / Ruby /你最喜欢的脚本语言.

也就是说,您可以非交互式使用Vim:

无声批处理模式

对于非常简单的文本处理(即使用Vim,如增强的’sed’或’awk’,可能只是受益于:substitute命令中的增强正则表达式),请使用Ex模式.

# Unix

vim -T dumb --noplugin -n -es -S "commands.ex" "filespec"

注意:如果“commands.ex”文件不存在,Vim将挂起等待输入;更好地检查它的存在!或者,Vim可以从stdin读取命令.您还可以使用从stdin读取的文本填充新缓冲区,如果使用 – 参数,则从stderr读取命令.

完全自动化

对于涉及多个窗口的更高级处理,以及Vim的真实自动化(您可以与用户交互或让Vim运行以让用户接管),请使用:

vim -N -u NONE -n -c "set nomore" -S "commands.vim" "filespec"

以下是使用的参数的摘要:

-T dumb Avoids errors in case the terminal detection goes wrong.

-N -u NONE Do not load vimrc and plugins,alternatively:

--noplugin Do not load plugins.

-n No swapfile.

-es Ex mode + silent batch mode -s-ex

Attention: Must be given in that order!

-S ... Source script.

-c 'set nomore' Suppress the more-prompt when the screen is filled

with messages or output to avoid blocking.

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值