Advertisement
Advertisement


How do I make Git use the editor of my choice for commits?


Question

I would prefer to write my commit messages in Vim, but it is opening them in Emacs.

How do I configure Git to always use Vim? Note that I want to do this globally, not just for a single project.

2017/04/06
1
2621
4/6/2017 8:13:02 PM

Accepted Answer

If you want to set the editor only for Git, do either (you don’t need both):

  • Set core.editor in your Git config: git config --global core.editor "vim"
  • Set the GIT_EDITOR environment variable: export GIT_EDITOR=vim

If you want to set the editor for Git and also other programs, set the standardized VISUAL and EDITOR environment variables*:

export VISUAL=vim
export EDITOR="$VISUAL"

* Setting both is not necessarily needed, but some programs may not use the more-correct VISUAL. See VISUAL vs. EDITOR.


For Sublime Text: Add this to the .gitconfig. The --wait is important (it allows to type text in sublime and will wait for save/close event.)

[core]
    editor = 'subl' --wait

'subl' can be replaced by the full path of the executable but is usually available when correctly installed.

2019/10/31
3591
10/31/2019 6:42:53 PM

Copy paste this:

git config --global core.editor "vim"

In case you'd like to know what you're doing. From man git-commit:

ENVIRONMENT AND CONFIGURATION VARIABLES

The editor used to edit the commit log message will be chosen from the GIT_EDITOR environment variable, the core.editor configuration variable, the VISUAL environment variable, or the EDITOR environment variable (in that order).

2020/06/20

On Ubuntu and also Debian (thanks @MichielB) changing the default editor is also possible by running:

sudo update-alternatives --config editor

Which will prompt the following:

There are 4 choices for the alternative editor (providing /usr/bin/editor).

  Selection    Path                Priority   Status
------------------------------------------------------------
  0            /bin/nano            40        auto mode
  1            /bin/ed             -100       manual mode
  2            /bin/nano            40        manual mode
* 3            /usr/bin/vim.basic   30        manual mode
  4            /usr/bin/vim.tiny    10        manual mode

Press enter to keep the current choice[*], or type selection number: 
2016/12/26

In windows 7, while adding the "Sublime" editor it was still giving me an error:

Aborting commit due to empty commit message.

Sublime was not able to keep the focus.

To fix this I opened the .gitconfig file in c:/users/username/ folder and added the following line with --wait option outside the double quotes.

[core]
      editor = 'F:/Program Files/Sublime Text 2/sublime_text.exe' --wait

Hope its helpful to somebody facing similar issue with Sublime.

2014/03/07

In Windows 7, setting editor to Notepad++

  • Open any text editor.
  • Open this file: C:\Users\YOUR_USERNAME\.gitconfig
  • Add this section to the bottom:

[core]
    editor = 'C:/Program Files (x86)/Notepad++/notepad++.exe' 
  • Save and close the file.
  • When you're committing with git, just write git commit and press Enter. It will pop open Notepad++.
  • Write your commit message at the top of the file, and save and close the file. Done!
2013/03/07

To Make Visual Studio Code (vscode) your default git editor

git config --global core.editor "code --wait"
2016/06/28

Source: https://stackoverflow.com/questions/2596805
Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Email: [email protected]