Change the default git editor
March 20, 2021 ‐ 2 min read
Many git commands can launch a text editor, for example the git commmit
command will launch one for you to enter the commit message. Git uses the editor that one of the environment variables VISUAL
or EDITOR
are set to in your shell. If none of them are set git will default to the vi
editor.
Of course you can set one of the VISUAL
or EDITOR
environment variables in your shell. But you can define your preferred editor also directly in the git config. You can change the git config file or via a command:
$ git config --global core.editor nvim
The git config file is either located in your home directory, named as: ~/.gitconfig
. Or you can use the location $XDG_CONFIG_HOME/git/config
, which most likely is ~/git/config
. This config file uses the TOML configuration language. You can add a default editor as follows:
# ~/git/config or ~/.gitconfig
[user]
email = koen@ko.en
name = Koen Woortman
[core]
editor = nvim
The value you set editor
to is actually the shell command used to launch the editor. So you are not just bound to terminal editors, you can for example use visual studio code as git editor as well.
Editor | Config value |
---|---|
nano | nano |
vim | vim |
neovim | nvim |
emacs | emacs |
sublime text | subl -n -w |
atom | atom --wait |
vscode | code --wait |