编辑git commit消息时自动进入插入模式 [英] Entering insert mode automatically when editing git commit messages
问题描述
如果我做了一个 git commit
,当Vim打开时,我想直接进入插入模式。
<我注意到编辑时
filetype
被设置为 gitcommit
,所以我想我可以通过自动命令。 au BufRead gitcommit startinsert!
这虽然行不通,但我做错了什么?
解决方案
我在 au中解决了FileType gitcommit executenormal!O| startinsert
在当前的上方添加一个新行,然后进入插入模式,准备输入消息。
<在:au事件模式命令
中,模式通常与缓冲区名称匹配。您可以使用 BufRead COMMIT_EDITMSG
来代替 BufRead gitcommit
。如果你想匹配filetype选项,那么使用 FileType
事件。
在线提交消息,我有一个自动命令(来自vimrc_example.vim),它没有
exenormal!g`\
每当我进入一个新的缓冲区时,如何
au FileType gitcommit 1 | startinsert
在进入插入模式之前进入第一行?现在我已经测试过了,我想我会保留它。)
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.
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. :)
这篇关于编辑git commit消息时自动进入插入模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!