Entering insert mode automatically when editing git commit messages

前端 未结 3 2179
难免孤独
难免孤独 2021-02-19 01:37

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 w

3条回答
  •  醉梦人生
    2021-02-19 02:24

    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. :)

提交回复
热议问题