Linux的sh文件保存时E212,Vim无法保存文件(E212)(Vim Can't Save File (E212))

Vim无法保存文件(E212)(Vim Can't Save File (E212))

有时当我使用vim some/path/newfile创建一个文件时,vim让我编辑它,只有在我试图保存更改时才会抱怨。

E212 Can't open file for writing.

这似乎只在新文件位于系统目录中时才会发生。

:w! 不会覆盖此错误。

我如何编写当前的缓冲区,而不必将其保存到临时位置,退出,然后使用sudo重命名它?

Sometimes when I create a file using vim some/path/newfile, vim lets me edit it, only to complain when I attempt to save my changes.

E212 Can't open file for writing.

This appears to happen only when the new file is located in a system directory.

:w! does not override this error.

How can I write the current buffer, without having to save it to a temporary location, exit, then rename it using sudo?

原文:https://stackoverflow.com/questions/14948441

更新时间:2019-10-26 19:12

最满意答案

这将要求您输入root密码,然后按照您的要求保存您的更改:

:w !sudo tee %

然后在提示符处输入(L)oad,在文件保存后重新加载文件。

This will ask you for the root password, then save your changes as you requested:

:w !sudo tee %

Then type (L)oad at the prompt, to re-load the file after it is saved.

2013-02-19

相关问答

sysct1.conf 可能无写权限! 查看方法:ls -lh /etc/sysct1.conf 如果没有,则chmod 666 /etc/sysctl.conf(root 用户)

sysct1.conf 可能无写权限! 查看方法:ls -lh /etc/sysct1.conf 如果没有,则chmod 666 /etc/sysctl.conf(root 用户)

这将要求您输入root密码,然后按照您的要求保存您的更改: :w !sudo tee %

然后在提示符处输入(L)oad,在文件保存后重新加载文件。 This will ask you for the root password, then save your changes as you requested: :w !sudo tee %

Then type (L)oad at the prompt, to re-load the file after it is saved.

http://vim.wikia.com/wiki/Diff_current_buffer_and_the_original_file 这是一个函数和命令来查看文件系统中当前编辑的文件与其未修改版本之间的差异。 只需把它放在你的vimrc或plugin目录下,打开一个文件,进行一些修改而不保存它们,并做:DiffSaved 。 function! s:DiffWithSaved()

let filetype=&ft

diffthis

vnew | r # | normal! 1Gdd

...

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.

Vim有一个内置的帮助系统,我刚才引用了它所说的:h E212 。 您可能希望将文件编辑为超级用户,如sudo vim FIL

...

那里没有太多的线索......用verbrose启动Vim打开gvim -V并执行:hardcopy可能会产生一些线索。 这也可能有用:set printexpr? 您还可以检查常规命令lps是否正常工作,并且您已正确设置默认打印机。 另一个有用的命令是set pdev=printer_name Not a lot of clues there... Starting Vim with verbose turned on gvim -V and doing :hardcopy might prod

...

你下面没有bin目录~ ( /Users/username )。 vim屏幕底部的"~/bin/git-diff.sh" [New DIRECTORY]的错误信息应该是一个提示 You don't have a bin directory below ~ (which is /Users/username). The error message of "~/bin/git-diff.sh" [New DIRECTORY] at the bottom of the vim screen should

...

:w filename

将保存到文件名 Enter :w filename in vi command mode, like @Yedidia said... I think you are confusing writing terminal output to a file. Which would be following command in order to create or overwrite text.txt: action > text.txt

and in order t

...

确保您有足够的访问权限将文件作为lufei打开,然后开始恢复: $ chmod u=rw resources/views/.user.blade.php.swp

$ vim -r resources/views/.user.blade.php.swp

This may be caused by the edit session crush like the items 2 in command sudo vim market/resources/views/user.blade.php. It

...

通过关闭控制台而不先退出Vim,Vim进程被杀死,Vim没有机会正常关闭。 Vim使用交换文件将最后未加载的更改存储到缓冲区,以避免在崩溃时丢失数据; 你可以阅读整个故事:help E325 。 在你的情况下,当你有意识地关闭控制台时,你的.bash_profile可能没有任何待定的更改[值得保存]。 (但是仍然有交换文件!)因此,在提示时 Swap file ".bash_profile.swp" already exists!

[O]pen Read-Only, (E)dit anyw

...

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值