devsetup1-8 Exercise 2: Set the Default Editor Everywhere ========================================================== STEP 1: SEE THE CURRENT STATE ----------------------------- readlink -f "$(command -v editor)" echo "EDITOR=$EDITOR" git config --global --get core.editor Before any change, editor usually points at nano, EDITOR is empty, and Git has no core.editor set (so it falls back to the system default). STEP 2: SET IT AT EACH LEVEL ---------------------------- # System-wide (pick from the list of installed editors) sudo update-alternatives --config editor # For your own account only select-editor # In your shell echo 'export EDITOR=vim' >> ~/.bashrc source ~/.bashrc # For Git git config --global core.editor "vim" Use whichever editor you are comfortable with in place of vim. STEP 3: PROVE EACH SETTING -------------------------- readlink -f "$(command -v editor)" # /usr/bin/vim.basic (or your choice) echo "$EDITOR" # vim git config --global --get core.editor # vim The exact path printed for the system default depends on which editor you chose. STEP 4: TRIGGER GIT'S EDITOR ---------------------------- mkdir -p ~/projects/editor-test && cd ~/projects/editor-test git init git commit --allow-empty The editor you chose opens with a commit message template. Save an empty message to cancel the commit (Git aborts on an empty message), or type a message to keep it. Then remove the test: cd .. && rm -rf editor-test If a different editor opens, the setting further up the chain is winning. Git looks at its own core.editor first, then environment variables such as GIT_EDITOR, VISUAL and EDITOR, and only then the system default. USING VS CODE FOR GIT INSTEAD ----------------------------- git config --global core.editor "code --wait" The --wait makes Git pause until you close the file in VS Code. Without it, Git sees the editor exit at once and aborts with an empty message. WHY THIS WORKS AS AN ANSWER --------------------------- It checks the state before changing anything, sets the choice at each level rather than relying on one, and proves the result by triggering the real behaviour. If the wrong editor opens, the order of precedence tells you which setting to look at.