How to Set Git Editor: Configure Your Preferred Text Editor for Git
To set your preferred editor in Git, use the command
git config --global core.editor "editor_command". Replace editor_command with the command to launch your editor, like code --wait for VS Code or nano for Nano.Syntax
The basic syntax to set the Git editor is:
git config: The Git command to change configuration.--global: Applies the setting for your user account globally.core.editor: The Git configuration key for the editor."editor_command": The command to launch your preferred text editor.
bash
git config --global core.editor "editor_command"Example
This example sets Visual Studio Code as the Git editor. The --wait flag tells VS Code to wait until the file is closed before returning control to Git.
bash
git config --global core.editor "code --wait"Common Pitfalls
Common mistakes include:
- Not using quotes around the editor command when it contains spaces or flags.
- Forgetting the
--waitflag for editors like VS Code or Sublime Text, which causes Git to think the editor closed immediately. - Setting the editor only locally (
--local) when you want it globally.
Example of wrong and right ways:
bash
git config --global core.editor "code --wait" # Right: quotes include the full command with flag git config --global core.editor code --wait # Wrong: missing quotes, Git treats 'code' as editor and '--wait' as extra argument
Quick Reference
| Editor | Command to Set in Git |
|---|---|
| Visual Studio Code | git config --global core.editor "code --wait" |
| Nano | git config --global core.editor "nano" |
| Vim | git config --global core.editor "vim" |
| Sublime Text | git config --global core.editor "subl -n -w" |
Key Takeaways
Use
git config --global core.editor "editor_command" to set your Git editor globally.Always quote the editor command if it includes spaces or flags.
Include the
--wait flag for GUI editors so Git waits for you to finish editing.You can set different editors like VS Code, Nano, Vim, or Sublime Text using their respective commands.
Check your editor setting anytime with
git config --global core.editor.