GitSetting Up an Editor

Setting Up an Editor

Git needs an editor for two common tasks: writing commit messages (when you run git commit without -m) and editing interactive rebase scripts. By default Git uses vi on macOS/Linux and Notepad on Windows. If neither is what you want, tell Git which editor to use instead.

Setting the default editor

core.editor

Bash
# Visual Studio Code
git config --global core.editor "code --wait"

# Sublime Text
git config --global core.editor "subl -n -w"

# Atom
git config --global core.editor "atom --wait"

# JetBrains editors (e.g., WebStorm, IntelliJ)
git config --global core.editor "webstorm --wait"

# Neovim
git config --global core.editor "nvim"

# Vim
git config --global core.editor "vim"

# Nano (easiest if you've never used a terminal editor)
git config --global core.editor "nano"

# Notepad++ on Windows
git config --global core.editor "'C:/Program Files/Notepad++/notepad++.exe' -multiInst -notabbar -nosession -noPlugin"

# Plain Notepad on Windows
git config --global core.editor "notepad"
Why --wait?
GUI editors like VS Code or Sublime spawn a window and return control to the terminal immediately. Git would think you already finished. The `--wait` flag (or `-w`) tells the editor to block until you close the file — which is exactly what Git needs.
The order Git uses to find an editor

Git checks, in order:

  • GIT_EDITOR environment variable

  • core.editor from git config

  • VISUAL environment variable

  • EDITOR environment variable

  • Falls back to vi (or Notepad on Windows)

If you have EDITOR set already (many developers do, for crontab, sudoedit, etc.), you may not need to set core.editor at all — Git will find it.

Set up VS Code as the editor (most common)

VS Code is by far the most popular editor in 2025. To wire it up:

Step 1: install VS Code

Bash
# Make sure 'code' works in your terminal.
# On macOS, open VS Code → Command Palette → "Shell Command: Install 'code' command in PATH"
# On Linux, install the .deb / .rpm.
# On Windows, the installer adds it to PATH by default.

code --version

Step 2: tell Git to use it

Bash
git config --global core.editor "code --wait"

Step 3: also use VS Code as the diff/merge tool (optional)

Bash
git config --global merge.tool vscode
git config --global mergetool.vscode.cmd 'code --wait --merge $REMOTE $LOCAL $BASE $MERGED'

git config --global diff.tool vscode
git config --global difftool.vscode.cmd 'code --wait --diff $LOCAL $REMOTE'
Testing it

Make a commit without -m

Bash
cd some-git-repo
echo "test" > demo.txt
git add demo.txt
git commit
# Your editor should open with the commit message template
The commit message template

When the editor opens for a commit, you see something like:

Commit message buffer

Text

# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
#
# On branch main
# Changes to be committed:
#       new file:   demo.txt
#

Type your message on the first line, save, and close the file. Git takes everything you wrote (minus comment lines) as the commit message.

Setting a personal commit message template

If your team uses a structured format, you can pre-populate the editor with a template.

~/.gitmessage

Bash
# <type>(<scope>): <subject>     (max 50 chars)
# |<--    body (max 72 chars per line)    -->|
#
# Why?
#
# Refs: #issue-id

Point Git at it

Bash
git config --global commit.template ~/.gitmessage
Common problems
  • “The git editor opened but Git did not wait for me.” You forgot the --wait flag. Add it.

  • “My editor command is not found.” Open a fresh terminal so the new PATH takes effect; verify with which code (macOS/Linux) or where code (Windows).

  • “I am stuck in vi.” Press Esc then type :wq and press Enter to save & quit, or :q! to quit without saving. Then git config --global core.editor "nano" so it does not happen again.

  • “Sublime never lets me commit.” Use subl -n -w-n opens a new window, -w blocks until close.

Tip
Whatever editor you pick, get comfortable with `Esc Esc Esc` — the universal “oh no get me out of here” — and remember that you can always abort a commit with an empty message; Git will cancel the commit cleanly.