To change the default text editor for Git, you can use the git config command. You can set the editor globally for all repositories or locally for a specific repository. Here’s how to do it:
To Set the Editor Globally
1. Open your terminal or command prompt.
2. Run the following command, replacing editor with the command for your preferred text editor. Here are a few examples:
- Vim:
git config --global core.editor "vim"
- Nano:
git config --global core.editor "nano"
- Visual Studio Code:
git config --global core.editor "code --wait"
- Sublime Text:
git config --global core.editor "subl -n -w"
- Notepad (Windows):
git config --global core.editor "notepad"
To Set the Editor for a Specific Repository
1. Navigate to the repository directory using your terminal.
2. Run the git config command without the --global flag:
git config core.editor "editor_command"
Verify the Configuration
To confirm that the editor has been set correctly, you can check the configuration by running:
git config --global --get core.editor
This will show the currently set global editor. If you're checking for a specific repository, omit the --global flag.
Notes
- Make sure that the editor command you provide is correctly installed and accessible from your terminal.
- The --wait flag (as used with editors like VS Code and Sublime) tells the editor to hold the terminal until the file is closed, which is important for Git commands that open the editor (like git commit).
Now, your Git operations that require an editor should use the specified text editor!