I’m at the stage where I’ve typed a commit message in Vim (which pops up when committing via Git), but I’m unsure how to proceed from there. I understand I need to vim save and quit, but the commands aren’t very intuitive.
What’s the correct way to save the message and exit Vim so the commit can go through?
I totally get the confusion, I was stuck the first time too! When you’re in Vim, after typing your commit message, hit Esc to make sure you’re in normal mode. Then type:
:wq
This stands for “write and quit.” Press Enter, and it’ll save your message and close Vim, allowing Git to continue with the commit. Simple as that!
Yeah, Vim’s all about modes. Once you’ve written your commit message, press Esc to enter normal mode, then type :wq or an even quicker option is ZZ (just shift + z twice). Both will save your commit message and quit Vim. If you want to exit without saving, :q! is your go-to command.
Once you get the hang of Vim, it becomes second nature — and it’s especially handy when you’re using it as your default editor for Git commits.
If Vim is feeling like a challenge, no worries, you can change your default editor in Git! For example, if you prefer Nano, run this command:
git config --global core.editor "nano"
But if you’re already in Vim:
- Press Esc to enter normal mode.
- Type :wq and hit Enter.
- Boom, your commit message is saved!
It took me a couple of tries to get comfortable with Vim too, but once you get the flow, saving and quitting is a breeze!