Entering insert mode automatically when editing git commit messages

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.

  • Which merge strategies does mercurial use?
  • The dependency `AFNetworking (~> 2.5)` is not used in any concrete target
  • How to push Tag to Bitbucket Git Repository in Bamboo from Cake build task?
  • Phantom file in github commit
  • Cygwin + msysgit - wrong line endings sent to commit message editor
  • Remove large .pack file created by git
  • au BufRead gitcommit startinsert!

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


    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.

  • Push Xcode Project to TFS Git repository
  • Put only a single file in git submodule/repository
  • git pull keeping local changes
  • How can I make Jenkins CI with git trigger on pushes to master?
  • How to avoid git conflicts in a team?
  • Git & redirections
  • 3 Solutions collect form web for “Entering insert mode automatically when editing git commit messages”

    In :au Event pattern command, the pattern is usually matched against the buffer name. Instead of BufRead gitcommit, you could use BufRead COMMIT_EDITMSG. If you want to match against the filetype option, then use the FileType event.

    I tend to write multi-line commit messages, and I have an autocommand (from vimrc_example.vim) that does

    exe "normal! g`\""

    whenever I enter a new buffer, so how about

    au FileType gitcommit 1 | startinsert

    to go to the first line before entering Insert mode? Now that I have tested it, I think I will keep it. 🙂

    An alternate approach:

    export GIT_EDITOR='vim +startinsert'

    or add ! in the end to start from the end of message (useful, when using git hooks for message completion)

    export GIT_EDITOR='vim +startinsert!'

    This is probably a bit more complex than it needs to be, but you can do this with an individual filetype plugin:

    $ mkdir -p ~/.vim/ftplugin/gitcommit
    $ echo 'startinsert!' > !$/git-commit-insert.vim
    Git Baby is a git and github fan, let's start git clone.