(Updated: )
/ #git #github #cli 

git/GitHub CLI set editor to vim or VSCode

The GitHub CLI (gh binary), defaults to nano as its editor.

Developers may want to set it to vim or VSCode to keep it in line with the git CLI’s behaviour.

Table of Contents

GitHub CLI (gh) set editor to vim/VSCode

Note: the following instructions work for any given editor that can be invoked using a CLI

Set the Editor for the GitHub CLI (gh) to vim:

gh config set editor "vim"

Or set the editor for the GitHub CLI (gh) to VSCode (code):

# ensure `code` CLI tool is installed using the VSCode command palette
gh config set editor "code --wait"

Git set editor to vim/VSCode

Note: the following instructions work for any given editor that can be invoked using a CLI

While researching how to set the editor for gh (the GitHub CLI), I found how to do the same for the main git CLI.

Set the git editor to vim:

# Using an env var for this command
GIT_EDITOR="vim" git commit
# Or using git config
git config --global core.editor vim

Set the git editor to VSCode:

# Using an env var for this command
GIT_EDITOR="code --wait" git commit
# Or using git config
git config --global core.editor "code --wait"

In order to override it globally, use the git config --global core.editor <editor-binary> or set the GIT_EDITOR env var in your rc file, eg. .bashrc, .zshrc etc.

Photo by Kelly Sikkema on Unsplash.

Author

Hugo Di Francesco

Co-author of "Professional JavaScript", "Front-End Development Projects with Vue.js" with Packt, "The Jest Handbook" (self-published). Hugo runs the Code with Hugo website helping over 100,000 developers every month and holds an MEng in Mathematical Computation from University College London (UCL). He has used JavaScript extensively to create scalable and performant platforms at companies such as Canon, Elsevier and (currently) Eurostar.

Get The Jest Handbook (100 pages)

Take your JavaScript testing to the next level by learning the ins and outs of Jest, the top JavaScript testing library.