[Developer's community]

Changing editor for Git

When using Git on the command line, you may encounter a challenge with the default editor when writing commit messages.

While typically, you can use the -m flag to include the commit message directly in the command like git commit -m "My commit text", sometimes you may need to amend a commit or accidentally run git commit without specifying a commit message. In these instances, you might be dropped into Vim...

Even if you're familiar with Linux and Vim, you'll face the need to recall a series of commands: pressing i to enter insert mode, typing the message, then hitting esc, followed by :, wq to save and exit. While the power of Vim is non-discussible, mastering Git on the command line is challenging enough without having to navigate an unfamiliar text editor.

The good news is that there's an easy way out. Depending on the OS (Windows/Mac OS/Linux), you can use an editor of your preference.

Using VS Code as the primary code editor across different platforms has become a de-facto standard for many of us. Hence, making use of it as a default editor for Git can be achieved with this simple command line expression:

git config --global core.editor "code --wait"

If you prefer using Notepad++ (as a Windows user), here's another command line expression that achieves exactly that:

git config --global core.editor "'C:/Program Files (x86)/Notepad++/notepad++.exe' -multiInst -notabbar -nosession -noPlugin"

And finally, on Mac, I usually use 'Nano' as a default text editor (which is also applicable to Linux users). To make it default for Git, just run:

git config --global core.editor "nano"

Happy coding!

 


Add comment

Loading