Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Entering insert mode automatically when editing git commit messages

Tags:

People also ask

Can I edit commit message in git?

You can change the most recent commit message using the git commit --amend command. In Git, the text of the commit message is part of the commit. Changing the commit message will change the commit ID--i.e., the SHA1 checksum that names the commit. Effectively, you are creating a new commit that replaces the old one.

How do I exit insert mode in git?

You may need to hit escape before :wq to exit the insert mode ( vi is a mode based editor). If you want to exit without saving hit escape, :q! and enter. git opens your default editor so you can edit the commit message. You can change the default editor, even to graphical text editors (such as Sublime Text).


If I do a git commit, when Vim opens, I want to be in insert mode straight away.

I noticed that the filetype is set to gitcommit when editing, so I thought I could achieve this with an autocommand.

au BufRead gitcommit startinsert!

This doesn't work though, what am I doing wrong?

SOLUTION

I settled on au FileType gitcommit execute "normal! O" | startinsert to add a new line above the current and then enter insert mode ready for entering a message.