The vi
editor is confusing if you’re not used to it. It takes a secret handshake to escape this application if you’ve stumbled into it. Here’s how to quit vi or vim on Linux, macOS, or any other Unix-like system.
如果您不习惯使用vi
编辑器,则会感到困惑。 如果您偶然发现该应用程序,则需要进行一次秘密握手才能退出该应用程序。 这是在Linux,macOS或任何其他类似Unix的系统上退出vi或vim的方法。
快速解答 (The Quick Answer)
If you’re in vi
or vim
and need to get out—with or without saving your changes—here’s how:
如果您使用的是vi
或vim
,需要保存或不保存所做的更改,那么请按照以下步骤操作:
First, press the Esc key a few times. This will ensure
vi
is out of Insert mode and in Command mode.首先,按几次Esc键。 这将确保
vi
退出插入模式和命令模式。Second, type
:q!
and press Enter. This tellsvi
to quit without saving any changes. (If you do want to save your changes, type:wq
instead.)其次,输入
:q!
然后按Enter。 这告诉vi
退出而不保存任何更改。 (如果确实要保存更改,请键入:wq
。)
If you want to learn the Linux command line, you’ll need to know a lot more than that. Read on and we’ll show you just how vi
works and why the instructions for quitting are so unusual. vi
is an important, powerful tool and the learning curve is worth it.
如果您想学习Linux命令行,则需要了解更多。 继续阅读,我们将向您展示vi
工作原理以及为什么退出说明如此不寻常。 vi
是一个重要而强大的工具,学习曲线值得。
vi,无所不在的编辑器 (vi, The Ubiquitous Editor)
Because vi
is everywhere the chances are you’re going to run up against it. You can even find yourself inside vi
by accident. Perhaps someone asks you to look at their Linux computer for them. You issue a command like crontab -e
, and vi
pops up. Surprise, someone has configured the default editor for crontab
to be vi
.
因为vi
无处不在,所以您将有机会与之抗衡。 您甚至可能偶然发现自己在vi
。 也许有人要您为他们看一下他们的Linux计算机。 您发出诸如crontab -e
类的命令,然后vi