vimrc 自动提交,带消息提示



>我在 vimrc 中使用以下命令在保存时自动提交。我觉得这非常有用。但是我不喜欢每次都使用相同的提交消息。

autocmd BufWritePost * execute ':silent ! if git rev-parse --git-dir > /dev/null 2>&1 ; then git add % ; git commit -m "Auto-commit: saved %"; fi > /dev/null 2>&1'

我想要的是在保存时收到提示,允许我在赶时间时提供提交消息或按回车键并使用"自动提交:保存%"作为默认值。

我玩弄了input(),在这个特定的命令中没有任何运气。

我还尝试使用函数返回的值,但也无法使其工作。

input()是一个

内置函数,您可以将其结果分配给变量,然后可以将其内容插入(通过适当的转义)到外部 shell 命令中:

autocmd BufWritePost * let message = input('Message? ', 'Auto-commit: saved ' . expand('%')) | execute ':silent ! if git rev-parse --git-dir > /dev/null 2>&1 ; then git add % ; git commit -m ' . shellescape(message, 1) . '; fi > /dev/null 2>&1'

这将在每次保存时查询。通过添加条件,您可以使其在未给出消息时中止提交。

最新更新