I like to use the command line for issuing git commands as much as possible, but when a merge occurs, emacs
is launched per my settings. If this happens in the VS Code Terminal, key bindings are not going to work well. Is there a way to have the VS Code terminal configured so that VS Code itself is used as the merge editor (but only when git
is called from the VS Code terminal)?
Asked
Active
Viewed 320 times
0
1 Answers
1
You can detect the TERM_PROGRAM
in your ~/.bashrc
or for that matter ~/.zshrc
depending on your shell:
if [ "$TERM_PROGRAM" = "vscode" ]
then
export GIT_EDITOR="code"
else
export GIT_EDITOR="emacs"
fi
Looking at man git-commit
you can see how git picks the appropriate editor, and you might want to simply set the EDITOR
environment variable instead of GIT_EDITOR
as other programs would benefit from this as well:
$ man git-commit | awk '/core.editor/' RS=
ENVIRONMENT AND CONFIGURATION VARIABLES
The editor used to edit the commit log message will be chosen from the
GIT_EDITOR environment variable, the core.editor configuration
variable, the VISUAL environment variable, or the EDITOR environment
variable (in that order). See git-var(1) for details.

Andreas Louv
- 46,145
- 13
- 104
- 123
-
Idk why I though you wore talking about commit messages. I'm not sure if the above would apply to merging? – Andreas Louv Jan 12 '21 at 16:53
-
I think you can tweak environment variables for VS Code and all parent processes should inherit that, so that script is obsolete. – Marek R Jan 12 '21 at 17:15
-
`GIT_EDITOR` worked well in my case, due to the precedence you pointed out - thanks! I maintain a form of dotfiles so this is actually useful to me regardless. – bbarker Jan 12 '21 at 17:21