I'm stuck and cannot escape. It says:
"type :quit<Enter> to quit VIM"
But when I type that it simply appears in the object body.
I'm stuck and cannot escape. It says:
"type :quit<Enter> to quit VIM"
But when I type that it simply appears in the object body.
This is for the worst-case scenario of exiting Vim if you just want out, have no idea what you've done and you don't care what will happen to the files you opened.
Ctrl-cEnterEnter
vi
EnterCtrl-\Ctrl-n:qa!
EnterThis should get you out most of the time.
Some interesting cases where you need something like this:
i
Ctrl-ovg
(you enter insert mode, then visual mode and then operator pending mode)Qappend
Enteri
Ctrl-ogQ
Ctrl-r=
Ctrl-k (thanks to porges for this case):set insertmode
(this is a case when Ctrl-\Ctrl-n returns you to normal mode)Edit: This answer was corrected due to cases above. It used to be:
EscEscEsc
:qa!
EnterHowever, that doesn't work if you have entered Ex mode. In that case you would need to do:
vi
Enter:qa!
EnterSo a complete command for "I don't want to know what I've done and I don't want to save anything, I just want out now!" would be
vi
EnterEscEscEsc:qa!
EnterAfter hitting ESC (or cmd + C on my computer) you must hit : for the command prompt to appear. Then, you may enter
quit
.You may find that the machine will not allow you to quit because your information hasn't been saved. If you'd like to quit anyway, enter ! directly after the quit (i.e.
:quit!
).Pictures are worth a thousand Unix commands and options:
I draw this to my students each semester and they seem to grasp vi afterwards.
vi is a finite state machine with only three states.
Upon starting, vi goes into COMMAND mode, where you can type short, few character commands, blindly. You know what you are doing; this isn't for amateurs.
When you want to actually edit text, you should go to INSERT mode with some one-character command:
Now, answering the question: exiting.
You can exit vi from EX mode:
w
andx
accept a file name parameter. If you started vi with a filename, you need not give it here again.At last, the most important: how can you reach EX mode?
EX mode is for long commands that you can see typing at the bottom line of the screen. From COMMAND mode, you push colon,
:
, and a colon will appear at the bottom line, where you can type the above commands.From INSERT mode, you need to push ESC, i.e. the Escape button, going to COMMAND mode, and then : to go to EX mode.
If you are unsure, push ESC and that will bring you to command mode.
So, the robust method is ESC-:-x-Enter which saves your file and quits.
Here is how you can exit Vim. Press Ctrl & 'Z' then 'X' and 'C'.
I got Vim by installing a Git client on Windows.
:q
wouldn't exit Vim for me.:exit
did however...I would like to add my two cents on this. The question has been asked here.
The
q
command with number closes the given split in that position.:q<split position>
or:<split position>q
will close the split in that position.Let's say your Vim window layout is as follows:
If you run the
q1
command, it will close the first split.q2
will close the second split and vice versa.The order of split position in the quit command does not matter.
:2q
or:q2
will close the second split.If the split position you pass to the command is greater than the number of current splits, it will simply close the last split.
For example, if you run the
q100
on the above window setup where there are only three splits, it will close the last split (Split 3).