bash :wq!导致 E212:无法打开文件进行写入按 ENTER 或键入命令继续

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/45921842/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 16:25:11  来源:igfitidea点击:

:wq! results in E212: Can't open file for writing Press ENTER or type command to continue

linuxbashvim

提问by TheBral

I am just trying to exit my vim file with :wq! but it gives me the error:

我只是想用 :wq 退出我的 vim 文件!但它给了我错误:

E212: Can't open file for writing Press ENTER or type command to continue

E212: Can't open file for writing Press ENTER or type command to continue

I press enter or type anything and it goes back to editing the file. Is there something wrong?

我按回车键或输入任何内容,然后返回编辑文件。有什么不对?

I am now stuck in my text editor.

我现在被困在我的文本编辑器中。

回答by Ingo Karkat

You can get more details about the error via :help E212:

您可以通过:help E212以下方式获取有关错误的更多详细信息:

For some reason the file you are writing to cannot be created or overwritten. The reason could be that you do not have permission to write in the directory or the file name is not valid.

由于某种原因,无法创建或覆盖您正在写入的文件。原因可能是您没有在目录中写入的权限或文件名无效。

If you don't need the changes any longer, just :q!and be done with it. For multiple Vim arguments, there's also :qall!.

如果您不再需要更改,只需:q!完成即可。对于多个 Vim 参数,还有:qall!.

If you do want to keep the changes, one approach is to investigate the permissions issue, e.g. in another terminal or via the file explorer, and fix the issue (e.g. via chmod/ chown).

如果您确实想保留更改,一种方法是调查权限问题,例如在另一个终端中或通过文件资源管理器,并修复问题(例如通过chmod/ chown)。

Alternatively, you can persist the changes elsewhere via :w /tmp/changes, then :quitVim, and then resolve the problem outside of Vim.

或者,您可以通过:w /tmp/changes,然后通过:quitVim在其他地方保留更改,然后在Vim 之外解决问题。

To address the "I'm stuck in Vim" (assuming it's not possible / tedious to start another session on the system): :suspendputs Vim in the background, and drops you into the original shell you started Vim from. :shellstarts a newshell from inside Vim, to which you return via exit.

为了解决“我被 Vim 卡住了”(假设在系统上启动另一个会话不可能/乏味)::suspend将 Vim 置于后台,并将您放入启动 Vim 的原始 shell。从 Vim 内部:shell启动一个新的shell,您可以通过exit.