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.
但当我输入它时,它就会出现在物体体中。
10 个解决方案
#1
3490
Hit the Esc key to enter "Normal mode". Then you can type :
to enter "Command-line mode". A colon (:
) will appear at the bottom of the screen and you can type in one of the following commands. To execute a command, press the Enter key.
点击Esc键进入“正常模式”。然后键入:输入“命令行模式”。冒号(:)将出现在屏幕的底部,您可以输入以下命令之一。要执行命令,请按Enter键。
-
:q
to quit (short for:quit
) - :q to quit (short for:quit)
-
:q!
to quit without saving (short for:quit!
) - :问!不存钱就辞职(辞职!)
-
:wq
to write and quit - :wq写作和退出。
-
:wq!
to write and quit even if file has only read permission (if file does not have write permission: force write) - :wq !即使文件只有读取权限(如果文件没有写权限:强制写入),也要写入和退出。
-
:x
to write and quit (similar to:wq
, but only write if there are changes) - :x写和退出(类似于:wq,但只有在有变化时才写)
-
:exit
to write and exit (same as:x
) - :退出写入和退出(同:x)
-
:qa
to quit all (short for:quitall
) - :qa to quitall (short for:quitall)
-
:cq
to quit without saving and make Vim return non-zero error (i.e. exit with error) - :cq退出不保存,使Vim返回非零错误(即错误退出)
You can also exit Vim directly from "Command mode" by typing ZZ
to save and quit (same as :x
) or ZQ
to just quit (same as :q!
). (Note that case is important here. ZZ
and zz
do not mean the same thing.)
您也可以直接从“命令模式”退出Vim,通过输入ZZ来保存和退出(相同的:x)或ZQ来退出(相同的:q!)。(注意这里的情况很重要。ZZ和ZZ的意思不一样。
Vim has extensive help - that you can access with the :help
command - where you can find answers to all your questions and a tutorial for beginners.
Vim有广泛的帮助——您可以访问:help命令——在那里您可以找到所有问题的答案和初学者的教程。
#2
124
Before you enter a command, hit the Esc key. After you enter it, hit the Return to confirm.
在您输入命令之前,点击Esc键。进入后,点击返回确认。
Esc finishes the current command and switches Vim to normal mode. Now if you press :, the :
will appear at the bottom of the screen. This confirms that you're actually typing a command and not editing the file.
Esc完成当前命令,并将Vim转换为正常模式。现在,如果你按下:,会出现在屏幕的底部。这确认您实际上是在输入一个命令,而不是编辑该文件。
Most commands have abbreviations, with optional part enclosed in brackets: c[ommand]
.
大多数命令都有缩写,可选部分包含在括号中:c[ommand]。
Commands marked with '*' are Vim-only (not implemented in Vi).
标有'*'的命令仅为vim(未在Vi中实现)。
Safe-quit (fails if there are unsaved changes):
安全退出(如果有未保存的更改失败):
-
:q[uit]
Quit the current window. Quit Vim if this is the last window. This fails when changes have been made in current buffer. - q[因纽特人]退出当前窗口。如果这是最后一个窗口,请退出Vim。当在当前缓冲区中进行更改时,此操作失败。
-
:qa[ll]
* Quit all windows and Vim, unless there are some buffers which have been changed. - :qa[ll]*放弃所有的windows和Vim,除非有一些已经改变的缓冲区。
Prompt-quit (prompts if there are unsaved changes)
提示-退出(如果有未保存的更改提示)
-
:conf[irm] q[uit]
* Quit, but give prompt when there are some buffers which have been changed. - :conf[irm] q[uit]退出,但当有一些缓冲区被改变时,请给出提示。
-
:conf[irm] xa[ll]
* Write all changed buffers and exit Vim. Bring up a prompt when some buffers cannot be written. - :conf[irm] xa[ll]* Write all changed buffer and exit Vim。当某些缓冲区无法写入时,提示提示。
Write (save) changes and quit:
写(保存)更改并退出:
-
:wq
Write the current file (even if it was not changed) and quit. Writing fails when the file is read-only or the buffer does not have a name.:wqa[ll]
* for all windows. - :wq写入当前文件(即使它没有改变)并退出。当文件为只读或缓冲区没有名称时,写入失败。所有windows:wqa(ll)*。
-
:wq!
The same, but writes even read-only files.:wqa[ll]!
* for all windows. - :wq !同样的,但写的是只读文件。:wqa(ll)!*对所有窗户。
-
:x[it]
,ZZ
(with details). Write the file only if it was changed and quit,:xa[ll]
* for all windows. - :x[它],ZZ(细节)。仅当文件被更改并退出时,才写入文件:xa[ll]* for all windows。
Discard changes and quit:
丢弃更改并退出:
-
:q[uit]!
ZQ
* Quit without writing, also when visible buffers have changes. Does not exit when there are changed hidden buffers. - :问(外的)!ZQ*退出时不写,也当可见缓冲区发生变化时。当有更改的隐藏缓冲区时,不退出。
-
:qa[ll]!
*,:quita[ll][!]
* Quit Vim, all changes to the buffers (including hidden) are lost. - :qa(ll)!*:quita[我][!*退出Vim,所有对缓冲区(包括隐藏)的更改都将丢失。
Press Return to confirm the command.
按Return键确认命令。
This answer doesn't reference all Vim write and quit commands and arguments. Indeed, they are referenced in the Vim documentation.
这个答案并不引用所有的Vim编写和退出命令和参数。实际上,它们在Vim文档中被引用。
Vim has extensive built-in help, type Esc:help
Return to open it.
Vim有广泛的内置帮助,类型Esc:helpReturn打开它。
This answer was inspired by the other one, originally authored by @dirvine and edited by other SO users. I've included more information from Vim reference, SO comments and some other sources. Differences for Vi and Vim are reflected too.
这个答案受到了另一个人的启发,最初是由@dirvine编写的,由其他用户编辑。我已经从Vim引用中包含了更多的信息,所以评论和其他一些来源。Vi和Vim的差异也得到了反映。
#3
62
If you want to quit without saving in vim and have vim return a non-zero exit code, you can use :cq
.
如果您想退出而不保存vim,并且有vim返回一个非零的退出代码,您可以使用:cq。
I use this all the time because I can't be bothered to pinky shift for !
. I often pipe things to vim which don't need to be saved in a file. We also have an odd SVN wrapper at work which must be exited with a non-zero value in order to abort a checkin.
我一直都在用这个,因为我根本就懒得去换。我经常把一些东西放到vim中,而vim不需要保存在文件中。我们在工作中也有一个奇怪的SVN包装器,它必须以非零值退出,以中止签入。
#4
52
Pictures worth a thousand unix commands and options:
价值一千个unix命令和选项的图片:
I draw this to my students each semester and they seem to grasp vi afterwards.
我每学期都把这个给我的学生看,他们似乎在后面抓住了vi。
vi is a finite state machine with only three states.
vi是只有三个状态的有限状态机。
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.
在开始时,vi进入命令模式,在那里您可以输入简短的,很少的字符命令,盲目的。你知道你在做什么,这不是业余的。
When you want to actually edit text, you should go to INSERT mode with some one-character command:
当您想要实际编辑文本时,您应该使用一些单字符命令来插入模式:
- i: go to INSERT in the place of the cursor
- i:到光标所在的位置。
- I: go to INSERT mode at the beginning of the line
- I:在开始的时候进入插入模式。
- a: append after the cursor
- a:在光标后面追加。
- A: append at the end of line
- A:在线的末端追加。
- o: open a new line below the current line
- o:在当前线以下新建一条线。
- O: open a new line in the place of the current line
- O:在当前线路的位置开通一条新线路。
Now, answering the question: exiting.
现在,回答这个问题:退出。
You can exit vi from EX mode:
你可以从EX模式退出vi:
- q: if you haven't made any modifications, or saved them beforehand
- 问:如果你没有做任何修改,或事先保存了它们。
- q!: ignores any modifications and quit
- 问!:忽略任何修改并退出。
- wq: save and quit
- wq:保存并退出
- x: this is equal to wq
- x:这等于wq。
w and x accept file name parameter. If you started vi with a filename, you need not give it here again.
w和x接受文件名参数。如果您使用一个文件名启动了vi,那么您就不必再在这里使用它了。
At last, the most important: how can you reach EX mode?
最后,最重要的是:怎样才能达到EX模式?
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.
EX模式是用于长命令,您可以在屏幕的底线看到输入。在命令模式下,您将冒号:在底线中出现冒号,您可以在其中键入上面的命令。
From INSERT mode, you need to push ESC, i.e. the Escape button, going to COMMAND mode, and then : to go to EX mode.
从插入模式,你需要push ESC,即Escape按钮,进入命令模式,然后:进入EX模式。
If you are unsure, push ESC and that will bring you to command mode.
如果你不确定,按ESC,这将使你进入命令模式。
So, the robust method is ESC-:-x-Enter which saves your file and quits.
因此,健壮的方法是ESC-:-x- enter,它保存您的文件并退出。
#5
35
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-cEnterEntervi
EnterCtrl-\Ctrl-n:qa!
Enter
Ctrl-cEnterEnterviEnterCtrl - \ Ctrl-n:qa !进去
This 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)iCtrl-ovg(进入插入模式,然后是可视模式,然后是操作符待定模式)
-
Qappend
EnterQappendEnter
-
i
Ctrl-ogQ
Ctrl-r=
Ctrl-k (thanks to porges for this case)iCtrl-ogQCtrl-r=Ctrl-k(感谢这一案例的porges)
-
:set insertmode
(this is a case when Ctrl-\Ctrl-n returns you to normal mode):设置insertmode(这是一个Ctrl-\Ctrl-n返回正常模式的情况)
Edit: This answer was corrected due to cases above. It used to be:
编辑:由于上面的案例,这个答案被纠正了。过去:
EscEscEsc:qa!
Enter
EscEscEsc:qa !进去
However, that doesn't work if you have entered Ex mode. In that case you would need to do:
但是,如果您已经输入了Ex模式,那么它就不起作用了。在这种情况下,你需要:
vi
Enter:qa!
Enter
这是因为:qa !进去
So 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!
Enter
viEnterEscEscEsc:qa !进去
#6
29
In case you need to exit Vim in easy mode (while using -y
option) you can enter normal Vim mode by hitting Ctrl + L and then any of the normal exiting options will work.
如果您需要在简单模式下退出Vim(同时使用-y选项),您可以按Ctrl + L进入正常的Vim模式,然后任何正常退出选项都可以工作。
#7
21
After hitting ESC (or cmd + C on my computer) you must hit : for the command prompt to appear. Then, you may enter quit
.
在使用ESC(或计算机上的cmd + C)之后,您必须点击:命令提示符出现。然后,您可以输入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!
).
您可能会发现,由于您的信息没有保存,机器不会允许您退出。如果你想退出,请进!在戒烟后(即:戒烟!)
#8
19
VIM has 3 modes of operation: Input mode, Command mode & Ex mode.
VIM有3种操作模式:输入模式、命令模式和Ex模式。
Input mode - everything that you type, all keystrokes are echoed on the screen.
输入模式——你键入的所有内容,所有击键都在屏幕上重复。
Command mode or Escape mode - everything that you type in this mode is interpreted as a command.
命令模式或转义模式——您在此模式中键入的所有内容都被解释为命令。
Ex mode - this is another editor, ex. It is a line editor. It works per line or based on a range of lines. In this mode, a : appears at the bottom of the screen. This is the ex editor.
Ex模式-这是另一个编辑器,它是一个行编辑器。它的工作原理是每行或基于一系列的线条。在这种模式下,a:出现在屏幕的底部。这是前任编辑。
In order to exit vim, you can exit while you are in either the ex mode or in the command mode. You cannot exit vim when you are in input mode.
为了退出vim,您可以在ex模式或命令模式下退出。当您处于输入模式时,您无法退出vim。
Exiting from ex mode
退出从交货模式
-
you need to be sure that you are in the Command mode. To do that, simply press the Escape key.
您需要确定您处于命令模式。要做到这一点,只需按下Escape键。
-
Go to the ex mode by pressing the : key
按下:键,进入ex模式。
-
Use any of the following combinations in ex mode to exit:
在ex模式下使用以下任何组合退出:
:q
- quit :q!
- quit without saving :wq
- save & quit or write & quit :wq!
- same as wq, but force write incase file permissions are readonly :x
- write & quit :qa
- quit all. useful when multiple files are opened like: vim abc.txt xyz.txt
:q -退出:问!-退出不存:wq - save & quit或write & quit:wq!-与wq相同,但强制写入incase文件权限是readonly:x - write & quit:qa - quit all。当多个文件打开时有用:vim abc。txt xyz.txt
Exiting from command mode
退出的命令模式
-
Press the escape key. You probably have done this already if you are in command mode.
按escape键。如果您处于命令模式,您可能已经这样做了。
-
press capital ZZ (
shift zz
) - save & exit按大写ZZ (shift ZZ) - save & exit。
-
press capital ZQ (
shift zq
) - exit without saving.按下ZQ (shift ZQ) -退出而不保存。
#9
12
I got Vim by installing a Git client on Windows. :q
wouldn't exit Vim for me. :exit
did however...
我在Windows上安装了一个Git客户机,从而获得了Vim。q不会为我退出Vim。然而:退出……
#10
1
I would like to add my 2 cents on this. The question has been asked here.
我想在这上面加上我的2分。这个问题已经提出来了。
The q
command with number closes the given split in that position.
带有数字的q命令会关闭该位置的给定分割。
:q<split position>
or :<split position>q
will close the split in that position.
:q
Lets say your vim window layout is as follows:
假设您的vim窗口布局如下:
-------------------------------------------------
| | | |
-------------------------------------------------
| | | |
| | | |
| Split 1 | Split 2 | Split 3 |
| | | |
-------------------------------------------------
If you run q1
command it will close the first split. q2
will close the second split and vice versa.
如果运行q1命令,它将关闭第一个拆分。q2将会关闭第二个分裂,反之亦然。
The order of split position in the quit command does not matter. :2q
or :q2
will close the second split.
在退出命令中,拆分位置的顺序无关紧要。:2q或:q2将结束第二次分裂。
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 3 splits, it will close the last split (Split 3).
例如,如果您在上面的窗口设置中运行q100,其中只有3个分割,那么它将关闭最后一个拆分(split 3)。
#1
3490
Hit the Esc key to enter "Normal mode". Then you can type :
to enter "Command-line mode". A colon (:
) will appear at the bottom of the screen and you can type in one of the following commands. To execute a command, press the Enter key.
点击Esc键进入“正常模式”。然后键入:输入“命令行模式”。冒号(:)将出现在屏幕的底部,您可以输入以下命令之一。要执行命令,请按Enter键。
-
:q
to quit (short for:quit
) - :q to quit (short for:quit)
-
:q!
to quit without saving (short for:quit!
) - :问!不存钱就辞职(辞职!)
-
:wq
to write and quit - :wq写作和退出。
-
:wq!
to write and quit even if file has only read permission (if file does not have write permission: force write) - :wq !即使文件只有读取权限(如果文件没有写权限:强制写入),也要写入和退出。
-
:x
to write and quit (similar to:wq
, but only write if there are changes) - :x写和退出(类似于:wq,但只有在有变化时才写)
-
:exit
to write and exit (same as:x
) - :退出写入和退出(同:x)
-
:qa
to quit all (short for:quitall
) - :qa to quitall (short for:quitall)
-
:cq
to quit without saving and make Vim return non-zero error (i.e. exit with error) - :cq退出不保存,使Vim返回非零错误(即错误退出)
You can also exit Vim directly from "Command mode" by typing ZZ
to save and quit (same as :x
) or ZQ
to just quit (same as :q!
). (Note that case is important here. ZZ
and zz
do not mean the same thing.)
您也可以直接从“命令模式”退出Vim,通过输入ZZ来保存和退出(相同的:x)或ZQ来退出(相同的:q!)。(注意这里的情况很重要。ZZ和ZZ的意思不一样。
Vim has extensive help - that you can access with the :help
command - where you can find answers to all your questions and a tutorial for beginners.
Vim有广泛的帮助——您可以访问:help命令——在那里您可以找到所有问题的答案和初学者的教程。
#2
124
Before you enter a command, hit the Esc key. After you enter it, hit the Return to confirm.
在您输入命令之前,点击Esc键。进入后,点击返回确认。
Esc finishes the current command and switches Vim to normal mode. Now if you press :, the :
will appear at the bottom of the screen. This confirms that you're actually typing a command and not editing the file.
Esc完成当前命令,并将Vim转换为正常模式。现在,如果你按下:,会出现在屏幕的底部。这确认您实际上是在输入一个命令,而不是编辑该文件。
Most commands have abbreviations, with optional part enclosed in brackets: c[ommand]
.
大多数命令都有缩写,可选部分包含在括号中:c[ommand]。
Commands marked with '*' are Vim-only (not implemented in Vi).
标有'*'的命令仅为vim(未在Vi中实现)。
Safe-quit (fails if there are unsaved changes):
安全退出(如果有未保存的更改失败):
-
:q[uit]
Quit the current window. Quit Vim if this is the last window. This fails when changes have been made in current buffer. - q[因纽特人]退出当前窗口。如果这是最后一个窗口,请退出Vim。当在当前缓冲区中进行更改时,此操作失败。
-
:qa[ll]
* Quit all windows and Vim, unless there are some buffers which have been changed. - :qa[ll]*放弃所有的windows和Vim,除非有一些已经改变的缓冲区。
Prompt-quit (prompts if there are unsaved changes)
提示-退出(如果有未保存的更改提示)
-
:conf[irm] q[uit]
* Quit, but give prompt when there are some buffers which have been changed. - :conf[irm] q[uit]退出,但当有一些缓冲区被改变时,请给出提示。
-
:conf[irm] xa[ll]
* Write all changed buffers and exit Vim. Bring up a prompt when some buffers cannot be written. - :conf[irm] xa[ll]* Write all changed buffer and exit Vim。当某些缓冲区无法写入时,提示提示。
Write (save) changes and quit:
写(保存)更改并退出:
-
:wq
Write the current file (even if it was not changed) and quit. Writing fails when the file is read-only or the buffer does not have a name.:wqa[ll]
* for all windows. - :wq写入当前文件(即使它没有改变)并退出。当文件为只读或缓冲区没有名称时,写入失败。所有windows:wqa(ll)*。
-
:wq!
The same, but writes even read-only files.:wqa[ll]!
* for all windows. - :wq !同样的,但写的是只读文件。:wqa(ll)!*对所有窗户。
-
:x[it]
,ZZ
(with details). Write the file only if it was changed and quit,:xa[ll]
* for all windows. - :x[它],ZZ(细节)。仅当文件被更改并退出时,才写入文件:xa[ll]* for all windows。
Discard changes and quit:
丢弃更改并退出:
-
:q[uit]!
ZQ
* Quit without writing, also when visible buffers have changes. Does not exit when there are changed hidden buffers. - :问(外的)!ZQ*退出时不写,也当可见缓冲区发生变化时。当有更改的隐藏缓冲区时,不退出。
-
:qa[ll]!
*,:quita[ll][!]
* Quit Vim, all changes to the buffers (including hidden) are lost. - :qa(ll)!*:quita[我][!*退出Vim,所有对缓冲区(包括隐藏)的更改都将丢失。
Press Return to confirm the command.
按Return键确认命令。
This answer doesn't reference all Vim write and quit commands and arguments. Indeed, they are referenced in the Vim documentation.
这个答案并不引用所有的Vim编写和退出命令和参数。实际上,它们在Vim文档中被引用。
Vim has extensive built-in help, type Esc:help
Return to open it.
Vim有广泛的内置帮助,类型Esc:helpReturn打开它。
This answer was inspired by the other one, originally authored by @dirvine and edited by other SO users. I've included more information from Vim reference, SO comments and some other sources. Differences for Vi and Vim are reflected too.
这个答案受到了另一个人的启发,最初是由@dirvine编写的,由其他用户编辑。我已经从Vim引用中包含了更多的信息,所以评论和其他一些来源。Vi和Vim的差异也得到了反映。
#3
62
If you want to quit without saving in vim and have vim return a non-zero exit code, you can use :cq
.
如果您想退出而不保存vim,并且有vim返回一个非零的退出代码,您可以使用:cq。
I use this all the time because I can't be bothered to pinky shift for !
. I often pipe things to vim which don't need to be saved in a file. We also have an odd SVN wrapper at work which must be exited with a non-zero value in order to abort a checkin.
我一直都在用这个,因为我根本就懒得去换。我经常把一些东西放到vim中,而vim不需要保存在文件中。我们在工作中也有一个奇怪的SVN包装器,它必须以非零值退出,以中止签入。
#4
52
Pictures worth a thousand unix commands and options:
价值一千个unix命令和选项的图片:
I draw this to my students each semester and they seem to grasp vi afterwards.
我每学期都把这个给我的学生看,他们似乎在后面抓住了vi。
vi is a finite state machine with only three states.
vi是只有三个状态的有限状态机。
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.
在开始时,vi进入命令模式,在那里您可以输入简短的,很少的字符命令,盲目的。你知道你在做什么,这不是业余的。
When you want to actually edit text, you should go to INSERT mode with some one-character command:
当您想要实际编辑文本时,您应该使用一些单字符命令来插入模式:
- i: go to INSERT in the place of the cursor
- i:到光标所在的位置。
- I: go to INSERT mode at the beginning of the line
- I:在开始的时候进入插入模式。
- a: append after the cursor
- a:在光标后面追加。
- A: append at the end of line
- A:在线的末端追加。
- o: open a new line below the current line
- o:在当前线以下新建一条线。
- O: open a new line in the place of the current line
- O:在当前线路的位置开通一条新线路。
Now, answering the question: exiting.
现在,回答这个问题:退出。
You can exit vi from EX mode:
你可以从EX模式退出vi:
- q: if you haven't made any modifications, or saved them beforehand
- 问:如果你没有做任何修改,或事先保存了它们。
- q!: ignores any modifications and quit
- 问!:忽略任何修改并退出。
- wq: save and quit
- wq:保存并退出
- x: this is equal to wq
- x:这等于wq。
w and x accept file name parameter. If you started vi with a filename, you need not give it here again.
w和x接受文件名参数。如果您使用一个文件名启动了vi,那么您就不必再在这里使用它了。
At last, the most important: how can you reach EX mode?
最后,最重要的是:怎样才能达到EX模式?
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.
EX模式是用于长命令,您可以在屏幕的底线看到输入。在命令模式下,您将冒号:在底线中出现冒号,您可以在其中键入上面的命令。
From INSERT mode, you need to push ESC, i.e. the Escape button, going to COMMAND mode, and then : to go to EX mode.
从插入模式,你需要push ESC,即Escape按钮,进入命令模式,然后:进入EX模式。
If you are unsure, push ESC and that will bring you to command mode.
如果你不确定,按ESC,这将使你进入命令模式。
So, the robust method is ESC-:-x-Enter which saves your file and quits.
因此,健壮的方法是ESC-:-x- enter,它保存您的文件并退出。
#5
35
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-cEnterEntervi
EnterCtrl-\Ctrl-n:qa!
Enter
Ctrl-cEnterEnterviEnterCtrl - \ Ctrl-n:qa !进去
This 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)iCtrl-ovg(进入插入模式,然后是可视模式,然后是操作符待定模式)
-
Qappend
EnterQappendEnter
-
i
Ctrl-ogQ
Ctrl-r=
Ctrl-k (thanks to porges for this case)iCtrl-ogQCtrl-r=Ctrl-k(感谢这一案例的porges)
-
:set insertmode
(this is a case when Ctrl-\Ctrl-n returns you to normal mode):设置insertmode(这是一个Ctrl-\Ctrl-n返回正常模式的情况)
Edit: This answer was corrected due to cases above. It used to be:
编辑:由于上面的案例,这个答案被纠正了。过去:
EscEscEsc:qa!
Enter
EscEscEsc:qa !进去
However, that doesn't work if you have entered Ex mode. In that case you would need to do:
但是,如果您已经输入了Ex模式,那么它就不起作用了。在这种情况下,你需要:
vi
Enter:qa!
Enter
这是因为:qa !进去
So 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!
Enter
viEnterEscEscEsc:qa !进去
#6
29
In case you need to exit Vim in easy mode (while using -y
option) you can enter normal Vim mode by hitting Ctrl + L and then any of the normal exiting options will work.
如果您需要在简单模式下退出Vim(同时使用-y选项),您可以按Ctrl + L进入正常的Vim模式,然后任何正常退出选项都可以工作。
#7
21
After hitting ESC (or cmd + C on my computer) you must hit : for the command prompt to appear. Then, you may enter quit
.
在使用ESC(或计算机上的cmd + C)之后,您必须点击:命令提示符出现。然后,您可以输入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!
).
您可能会发现,由于您的信息没有保存,机器不会允许您退出。如果你想退出,请进!在戒烟后(即:戒烟!)
#8
19
VIM has 3 modes of operation: Input mode, Command mode & Ex mode.
VIM有3种操作模式:输入模式、命令模式和Ex模式。
Input mode - everything that you type, all keystrokes are echoed on the screen.
输入模式——你键入的所有内容,所有击键都在屏幕上重复。
Command mode or Escape mode - everything that you type in this mode is interpreted as a command.
命令模式或转义模式——您在此模式中键入的所有内容都被解释为命令。
Ex mode - this is another editor, ex. It is a line editor. It works per line or based on a range of lines. In this mode, a : appears at the bottom of the screen. This is the ex editor.
Ex模式-这是另一个编辑器,它是一个行编辑器。它的工作原理是每行或基于一系列的线条。在这种模式下,a:出现在屏幕的底部。这是前任编辑。
In order to exit vim, you can exit while you are in either the ex mode or in the command mode. You cannot exit vim when you are in input mode.
为了退出vim,您可以在ex模式或命令模式下退出。当您处于输入模式时,您无法退出vim。
Exiting from ex mode
退出从交货模式
-
you need to be sure that you are in the Command mode. To do that, simply press the Escape key.
您需要确定您处于命令模式。要做到这一点,只需按下Escape键。
-
Go to the ex mode by pressing the : key
按下:键,进入ex模式。
-
Use any of the following combinations in ex mode to exit:
在ex模式下使用以下任何组合退出:
:q
- quit :q!
- quit without saving :wq
- save & quit or write & quit :wq!
- same as wq, but force write incase file permissions are readonly :x
- write & quit :qa
- quit all. useful when multiple files are opened like: vim abc.txt xyz.txt
:q -退出:问!-退出不存:wq - save & quit或write & quit:wq!-与wq相同,但强制写入incase文件权限是readonly:x - write & quit:qa - quit all。当多个文件打开时有用:vim abc。txt xyz.txt
Exiting from command mode
退出的命令模式
-
Press the escape key. You probably have done this already if you are in command mode.
按escape键。如果您处于命令模式,您可能已经这样做了。
-
press capital ZZ (
shift zz
) - save & exit按大写ZZ (shift ZZ) - save & exit。
-
press capital ZQ (
shift zq
) - exit without saving.按下ZQ (shift ZQ) -退出而不保存。
#9
12
I got Vim by installing a Git client on Windows. :q
wouldn't exit Vim for me. :exit
did however...
我在Windows上安装了一个Git客户机,从而获得了Vim。q不会为我退出Vim。然而:退出……
#10
1
I would like to add my 2 cents on this. The question has been asked here.
我想在这上面加上我的2分。这个问题已经提出来了。
The q
command with number closes the given split in that position.
带有数字的q命令会关闭该位置的给定分割。
:q<split position>
or :<split position>q
will close the split in that position.
:q
Lets say your vim window layout is as follows:
假设您的vim窗口布局如下:
-------------------------------------------------
| | | |
-------------------------------------------------
| | | |
| | | |
| Split 1 | Split 2 | Split 3 |
| | | |
-------------------------------------------------
If you run q1
command it will close the first split. q2
will close the second split and vice versa.
如果运行q1命令,它将关闭第一个拆分。q2将会关闭第二个分裂,反之亦然。
The order of split position in the quit command does not matter. :2q
or :q2
will close the second split.
在退出命令中,拆分位置的顺序无关紧要。:2q或:q2将结束第二次分裂。
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 3 splits, it will close the last split (Split 3).
例如,如果您在上面的窗口设置中运行q100,其中只有3个分割,那么它将关闭最后一个拆分(split 3)。