There are two vim options to do what you want: vim -v Start Vim in Vi mode, just like the executable was called 'vi'. This only has effect when the executable is called 'ex'. Vim -C Compatible. Set the 'compatible' option. This will make Vim behave mostly like Vi, even though a.vimrc file exists. It looks like you're inside the vi editor. Typing:wq and pressing enter should do it, i.e. Save the commit message and exit.: enters the command mode, w is for 'write' (save) and q is for 'quit'. You may need to hit escape before:wq to exit the insert mode (vi is a mode based editor). If you want to exit without saving hit escape,:q! Git opens your default editor so you can edit. After you have completed it a few times, open an existing (non-important) text file and try out all the things you learned from vimtutor: entering/leaving insert mode, undoing changes, quitting/saving, yanking/putting, moving and so on.
Quit Vim if this is the last window. This fails when changes have been made in current buffer.:qa ll. Quit all windows and Vim, unless there are some buffers which have been changed. Prompt-quit (prompts if there are unsaved changes). Create a custom mapping for frequenly used tasks. If you quit vim often, create a mapping with few key strokes, e.g. Nnoremap:xa If the is set to comma using let mapleader = ',' hitting comma twice is a quick way of quitting vim and saving your changes. If you want to save one more key stroke when you are in.
Keith CollinsTech Reporter
“How to exit the Vim editor?”
That was a question asked by Stack Overflow user jclancy on August 6, 2012. If you don’t know, Vim is a text editor in which programmers write and edit code, and this question is just what it looks like: jclancy opened Vim, and couldn’t figure out how to close it. The question has more than a thousand upvotes, seven detailed answers, and has now been visited more than a million times, according to a blog post on Stack Overflow.
The difficulty of using Vim has been a running joke among programmers for years. To understand why, if you’re using a Mac or Linux computer, open the Terminal application. At the command prompt, type vim test.txt
. That will create a text file, test.txt
, which will open in Vim. Now try to close it and get back to the command prompt. If you can’t figure it out, just know that thousands of expert programmers who came before you couldn’t figure it out either.
In fact, according to the blog post on Stack Overflow, about 80 people visit this question every hour during work days. So if you’re still stuck, don’t worry, we’ll explain what to do below.
The first thing many programmers may do to try to get out of Vim is press control-c, or type quit
, or type exit
, or maybe exit()
. None of these will work. If you press enough buttons, you might see the message jclancy saw: “type :quit<Enter> to quit VIM.” If so, you’ll probably try to type :quit
and press enter, because you’re a perfectly reasonable person. But that won’t work either. As dirvine says in their answer to jclancy’s question, you have to hit the escape key first.
“Hit the Esc key,” dirvine says. Once you hit escape, “vim goes into command mode.” From there, dirvine offers nine commands you can enter to actually get out of Vim:
- :q to quit (short for :quit)
- :q! to quit without saving (short for :quit!)
- :wq to write and quit (think write and quit)
- :wq! to write and quit even if file has only read permission (if file does not have write permission: force write)
- :x to write and quit (similar to :wq, but won’t write if there are no changes)
- :qa to quit all (short for :quitall)
- When you press :, a : will appear at the bottom of the screen.
- Or you can press Esc ZZ (Esc Shift+Z Shift+Z) to write/save if the file was changed, then quit.
- Or if you don’t want to save changes you can use ZQ instead.
See? It’s that easy. You won’t want to save the text file you created earlier, so just press escape, then type :q
, and it will all be over. Phew.
The reason Vim can be so difficult for newcomers to use is because it’s actually built for maximum productivity. Experienced Vim users tend not to use their mouse, because Vim provides a complex, robust keyboard shortcutting system that is almost a language in itself. And despite its high learning curve, Vim was the fourth most popular text editing tool among the 64,000 programmers who took Stack Overflow’s most recent developer survey.
The Vim editor is also free, and ships with most modern operating systems. So now that you’ve had a taste, if you want to explore the full horror and beauty that is the Vim editor, try this video game, VIM Adventures, which forces you to use Vim keyboard combinations to move around a world. If you don’t rage quit within five minutes, you may have just found your new favorite text editor.