在 Vim 中保存文件后如何自动执行 shell 命令? [英] How to automatically execute a shell command after saving a file in Vim?

查看:27
本文介绍了在 Vim 中保存文件后如何自动执行 shell 命令?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是因为我想在每个文件保存后自动运行测试.

This is because I'd like to automatically run tests after each file save.

我已经查看了 autocmdBufWritePost 但无法使其工作.

I have looked at autocmd and BufWritePost but cannot make it work.

推荐答案

这会在保存任何文件后运行 run_tests.sh,以当前文件名作为唯一参数:

This runs run_tests.sh after any file is saved, with the current filename as the only parameter:

:autocmd BufWritePost * !run_tests.sh <afile>

查看自动命令:

:autocmd BufWritePost *

并删除之前的所有自动命令:

And remove all auto-commands from the previous with:

:autocmd! BufWritePost *

这篇关于在 Vim 中保存文件后如何自动执行 shell 命令?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆