Vim for Windows - What do I type to save and exit from a file?

GitVimWindows XpGit Commit

Git Problem Overview


Using Windows XP I accidentally typed git commit -a instead of git commit -am "My commit message", and now I'm viewing my CMD prompt filled with the file version of my commit message ("Please enter the commit message for your..."). I've added my message to the top, but now I can't figure out how to save and leave. I tried to press Ctrl + W + Q, but it doesn't do anything, but add ^ where the cursor is.

I also tried Esc first, and then Ctrl + W + Q, but it says No write since last change (add ! to override).

Git Solutions


Solution 1 - Git

Press ESC to make sure you are out of the edit mode and then type:

:wq

Solution 2 - Git

Instead of telling you how you could execute a certain command (Esc:wq), I can provide you two links that may help you with VIM:

However, the best way to learn Vim is not only using it for Git commits, but as a regular editor for your everyday work.

If you're not going to switch to Vim, it's nonsense to keep its commands in mind. In that case, go and set up your favourite editor to use with Git.

Solution 3 - Git

Esc to make sure you exit insert mode, then :wq (colon w q) or ZZ (shift-Z shift-Z).

Solution 4 - Git

  • Press i or a to get into insert mode, and type the message of choice

  • Press ESC several times to get out of insert mode, or any other mode you might have run into by accident

  • to save, :wq, :x or ZZ

  • to exit without saving, :q! or ZQ

To reload a file and undo all changes you have made...:

Press several times ESC and then enter :e!.

Solution 5 - Git

A faster way to

  • Save
  • and quit

would be

:x

If you have opened multiple files you may need to do a

:xa

Solution 6 - Git

:q! will force an unconditional no-save exit

Solution 7 - Git

Use:

:wq!

The exclamation mark is used for overriding read-only mode.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionorokusakiView Question on Stackoverflow
Solution 1 - GitnunopoloniaView Answer on Stackoverflow
Solution 2 - GiteckesView Answer on Stackoverflow
Solution 3 - GitephemientView Answer on Stackoverflow
Solution 4 - GitsjasView Answer on Stackoverflow
Solution 5 - GitFabian SchuhView Answer on Stackoverflow
Solution 6 - GitMarc BView Answer on Stackoverflow
Solution 7 - GitHedegoView Answer on Stackoverflow