vimrc自动提交带有消息提示 [英] vimrc auto-commit w/message prompt

查看:83
本文介绍了vimrc自动提交带有消息提示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在vimrc中使用以下命令在保存时自动提交.我觉得这很有用.但是我不喜欢每次都停留在同一条提交消息上.

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.

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'

我想要的是在保存时收到提示,该提示使我可以提供提交消息或按Enter键,并在需要时使用自动提交:已保存的百分比"作为默认值.

What I would like is to receive a prompt when saving that allows me to either provide a commit message or press enter and use the "Auto-commit: saved %" as a default when I am in a hurry.

我和input()一起玩耍,在这个特定命令中没有任何运气.

I played around with input() and didnt have any luck within this particular command.

我还尝试使用函数返回的值,但也无法使它起作用.

I also attempted to use a value returned by a function but could not get that to work either.

推荐答案

input()是内置函数,您将其结果分配给变量,然后可以将其内容(适当地转义)插入外部外壳程序中命令:

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.

这篇关于vimrc自动提交带有消息提示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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