Welcome to 16892 Developer Community-Open, Learning,Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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)?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
2.8k views
Welcome To Ask or Share your Answers For Others

1 Answer

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.

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to 16892 Developer Community-Open, Learning and Share
...