To configure Git to use a specific editor globally (e.g., Vim, Nano, VS Code) for commit messages, use the git config command to set the core.editor setting. Here’s how:
1. Set the Default Editor Globally
git config --global core.editor "vim"
- Replace
vimwith your preferred editor’s command (e.g.,nano,code --wait,subl -n -w). - This applies to all repositories on your system.
2. Common Editor Examples
| Editor | Command |
|---|---|
| Vim | git config --global core.editor "vim" |
| Nano | git config --global core.editor "nano" |
| VS Code | git config --global core.editor "code --wait" |
| Sublime Text | git config --global core.editor "subl -n -w" |
| Emacs | git config --global core.editor "emacs" |
3. Verify the Configuration
git config --global --get core.editor
This returns the configured editor (e.g., vim).
4. Temporarily Override for a Single Commit
Use the GIT_EDITOR environment variable:
GIT_EDITOR=nano git commit
Notes
- VS Code/IDEs: Use
--waitto force Git to wait until the editor closes. - Windows Paths: Use the full path if the editor isn’t in your
PATH(e.g.,"C:/Program Files/Notepad++/notepad++.exe"). - System Default: Git uses your
$EDITORshell variable ifcore.editorisn’t set.
Troubleshooting
- Editor Not Opening: Ensure the editor command is installed and accessible in your terminal.
- Spaces in Paths: Wrap paths in quotes (e.g.,
"C:/Program Files/..."). - Test with a Commit:
git commit # Should open your configured editor
By configuring this once, you’ll streamline your Git workflow!