skip to Main Content

I’m trying to set up git so that the vim editor opens when I do git commit without a message. Previously I had set up VSCode do this, but it wasn’t working, it was giving me the error "aborting due to empty message" before opening VSCode. I then see a COMMIT_EDITMSG file in VSCode for me to edit, but editing and saving it does not cause the commit to go through.

I tried to change the editor to vim instead, entering git config --global "vim -w and git config --global core.editor vim based on other StackOverflow answers. git config --get core.editor confirms that git is now configured to use vim as the editor. But git commit still aborts before I can enter a commit message, and then opens VSCode. I’d rather just go back to using vim than try to fix whatever is going on in VSCode, since I prefer vim.

2

Answers


  1. Chosen as BEST ANSWER

    Per discussion in comments, the cause of the problem was GIT_EDITOR had been set to code, and the solution was unset GIT_EDITOR.


  2. There are several places git looks for the editor to use, this is explained well in git-var manpage:

    GIT_EDITOR

    Text editor for use by Git commands. The value is meant to be interpreted by the shell when it is used. Examples: ~/bin/vi, $SOME_ENVIRONMENT_VARIABLE, "C:Program FilesVimgvim.exe" --nofork. The order of preference is the $GIT_EDITOR environment variable, then core.editor configuration, then $VISUAL, then $EDITOR, and then the default chosen at compile time, which is usually vi.

    As you have discovered, you had GIT_EDITOR set and that is considered before core.editor.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search