Shell 有没有办法调用vim宏';什么是内壳脚本?
我正在unix环境中使用shell脚本和vim宏进行数据处理。以下是步骤:Shell 有没有办法调用vim宏';什么是内壳脚本?,shell,vim,Shell,Vim,我正在unix环境中使用shell脚本和vim宏进行数据处理。以下是步骤: 我使用grep从日志文件中获取一些有用的行 vim中的宏用于操作数据 同样,使用shell脚本来处理数据 我必须为许多文件执行此操作。所以,我想知道是否有一种方法可以通过特殊的包装器在shell脚本中调用vim的宏 我不清楚你的要求。但是也许vim-s,vim-W,vim-W可以帮助你 您可以触发录制的宏,例如 $ vim -c "normal! @q" file 这是一种脆弱的做法 选择 除非您真的需要特殊的Vim功
我必须为许多文件执行此操作。所以,我想知道是否有一种方法可以通过特殊的包装器在shell脚本中调用vim的宏 我不清楚你的要求。但是也许vim-s,vim-W,vim-W可以帮助你 您可以触发录制的宏,例如
$ vim -c "normal! @q" file
这是一种脆弱的做法
选择
除非您真的需要特殊的Vim功能,否则最好使用非交互式工具,如sed
、awk
,或Perl/Python/Ruby/您最喜欢的脚本语言
也就是说,您可以非交互地使用Vim:
静默批处理模式
对于非常简单的文本处理(即使用Vim,如增强的“sed”或“awk”,可能只是得益于:substitute
命令中增强的正则表达式),请使用Ex模式
注意:静默批处理模式-s-ex
会弄乱Windows控制台,因此您可能需要
执行cls
以在Vim运行后进行清理
# Unix
vim -T dumb --noplugin -n -es -S "commands.ex" "filespec"
注意:如果“commands.ex”文件不正确,Vim将挂起等待输入
存在;最好事先检查它的存在!或者,Vim可以读取
来自stdin的命令。您还可以用从中读取的文本填充新缓冲区
如果使用-参数,则从stderr读取命令
全自动化
用于涉及多个窗口的更高级处理和真正的自动化
Vim(您可以在其中与用户交互,或者让Vim运行以让
用户接管),使用:
以下是所用参数的摘要:
-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.
谢谢这有助于我做得更好。因为我喜欢vim macro的魔力,所以我已经使用了awk和sed。
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.