Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
3.2k views
in Technique[技术] by (71.8m points)

How to prevent the standard git merge editor from being used in the VS Code terminal?

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...