0

When I commit to git, I generally enter my message in Vi and then type :wq but just occasionally I miss and type :Wq which is clearly invalid. The problem is that when I do this, Vi exits with return code 1. Git sees this and thinks I aborted the commit and so I lose my commit message.

What I want is to still be able to abort a commit with :cq - so changing git to ignore the error is not ideal (although if no-one knows of anything else then I'd go for that) but to be able to still commit correctly when I've typed :Wq accidentally.

4
  • This doesn't quite make sense. If you :Wq, vim should spit an error at you but leave you still inside vim. Then if you execute the proper :wq, it would write and exit normally.
    – phemmer
    Mar 13, 2018 at 12:40
  • That is exactly what happens, then when I type :wq it writes the file and quits with a return code of 1 - which git rightly interprets to mean that the editor failed in some way.
    – mjaggard
    Mar 14, 2018 at 16:28
  • That's not "exit normally" :-). My vim does not exhibit the behavior you describe. If I :Wq then :wq, vim exits status 0.
    – phemmer
    Mar 14, 2018 at 17:22
  • Good point. It seems that my Ubuntu box doesn't show this issue by MacOS does.
    – mjaggard
    Mar 15, 2018 at 14:32

1 Answer 1

3

Simply add

cabbrev Wq wq

to your .vimrc file. This will make :Wq an alias for :wq.

1
  • I did this in March last year and had no problems until today when I typed :WQ :-(
    – mjaggard
    Aug 19, 2019 at 15:47

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .