Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Open Git commit editor to specific cursor location

Tags:

git

vim

I have modified my prepare-commit-msg hook to include the branch name at the beginning of my commit message (e.g. [JCH-234] -). However, when I run git commit the cursor is located at the beginning of the editor Vim. I'm looking for a way to start the cursor at the location following my branch name.

I'm aware that it's only a few extra key strokes to move the cursor however, I believe in attention to detail and would like to implement this if possible.

like image 375
Jake Henningsgaard Avatar asked Feb 06 '23 12:02

Jake Henningsgaard


1 Answers

IMO, this is git config thing, we shouldn't add special vim script/config for it.

You can set GIT_EDITOR variable like:

GIT_EDITOR="vim -c'startinsert|norm! ggA'"

This makes everytime you git commit, git will hook your pre-commit-msg, then open vim, put cursor at the end of the first line, in your case, after your branch name, also switch to insert mode.

like image 115
Kent Avatar answered Feb 08 '23 15:02

Kent