When I'm using git
command in the built-in VSCode terminal, for things like editing commit message or proceeding with interactive rebase, it spawns its own, CLI-based editor. That's regular Git behavior but it doesn't really make sense in this context. I have a full-featured editor already open! Why to open another one? It's one of that little insignificant things that annoy me from quite some time, but I never had a motivation to do anything with them. But finally I did! At least that one.
Running an editor within an editor was a bit awkward thing by itself, but what really pushed me to take the action was broken keyboard shortcuts. VSCode doesn't work well with Nano (this is CLI editor I'm using) running inside the built-in terminal. It intercepts Ctrl+K
combination that cuts the selected line in Nano
so effectively such a basic feature as copy-paste doesn't work. That really breaks the whole point of interactive rebase as re-ordering commits needs copying and pasting.
Configuring an editor used by Git is easy. git config --global core.editor 'code --wait'
should do the trick (I found the hint about a parameter required here). The thing is, I don't really want to get rid of Nano. It works well when I do things in a standalone terminal. So, is it even possible to set this setting conditionally, depending on where you call git
commands? To eat a cake and have a cake?
After some digging, I found quite a surprising answer to a question I'd never ask, as I did it once and simlpy memoized the answer, which apparently wasn't full. It turns out, that if there is no editor set in the config, Git searches environment variables: GIT_EDITOR
and EDITOR
. The later is (at least theoretically) used by other CLI programs too, so I decided to use it.
How to make it work as a charm
- Open command palette (
Ctrl/Cmd + P
) - Type
>Open settings JSON
and confirm withEnter
- Add the following lines to your JSON config, adjusting the operating system name when needed
"terminal.integrated.env.osx": {
"EDITOR": "code --wait"
}
- Open
~/.gitconfig
file - Remove the line containing the configuration of the editor (it was
editor = nano
in my case) - Open
~/.bashrc
,~/.zshrc
or any other file configuring your shell - Paste a snippet there (choose whatever editor you've had before in your Git config):
if [[ -z "$EDITOR" ]]; then
export EDITOR="nano"
fi
Et voilà!
In the Terminal app the same git
command launches Nano, as expected.
Enjoy 😀
Top comments (0)