vimrc auto-commit w/message prompt

前端 未结 1 1922
暗喜
暗喜 2020-12-22 04:49

I use the following command in my vimrc to auto commit on save. I find this very useful. However I do not like that I am stuck with the same commit message every time.

相关标签:
1条回答
  • 2020-12-22 05:03

    input() is a built-in function, you assign its result to a variable, and can then insert (with proper escaping) its contents into your external shell command:

    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'

    This one will query on every save. With an added conditional, you could make it abort the commit when no message is given.

    0 讨论(0)
提交回复
热议问题