File Can';当vim使用swp文件恢复文件时,不能打开文件进行写入

File Can';当vim使用swp文件恢复文件时,不能打开文件进行写入,file,vim,editor,backup,temporary-files,File,Vim,Editor,Backup,Temporary Files,我想恢复/home/lufei/market/resources/views/user.blade.php,这里是swp文件的位置 > lufei@localhost:~/market$ ls resources/views/.user.blade.php.swp > resources/views/.user.blade.php.swp 我使用vim-r resources/views/.user.blade.php.swp来恢复文件,我得到 E306:无法打开resource

我想恢复
/home/lufei/market/resources/views/user.blade.php
,这里是
swp
文件的位置

> lufei@localhost:~/market$ ls resources/views/.user.blade.php.swp 
> resources/views/.user.blade.php.swp
我使用
vim-r resources/views/.user.blade.php.swp
来恢复文件,我得到

E306:无法打开resources/views/.user.blade.php.swp按ENTER键或 键入命令以继续

当我使用
sudo vim-r resources/views/.user.blade.php.swp
时,我可以打开该文件,但当我在vim中使用
:wq
时,我得到

“/root/market/resources/views/user.blade.php”
“/root/market/resources/views/user.blade.php”E212:无法打开文件 要进行写入,请按ENTER键或键入command继续

根据上面的信息,我认为vim希望将文件保存到根目录。从中,我想如果我创建路径
/root/market/resources/views/
可能会起作用。但是我想直接将文件保存到正确的位置
/home/lufei/market/resources/views/user.blade.php
。所以我使用
su&&cd/home/lufei/market
然后使用
vim-r resources/views/.user.blade.php.swp
。但是当我在vim中
:wq
时,我也会

"~/market/resources/views/user.blade.php"                                                        
"~/market/resources/views/user.blade.php" E212: Can't open file for writing
Press ENTER or type command to continue
通过以上尝试,无论我使用普通用户还是根用户,当我恢复文件时,vim都会尝试将文件保存到不存在路径的错误位置


我是否可以直接将文件恢复到正确的位置,而无需创建临时路径,然后将恢复的文件复制回正确的路径。

请确保您有足够的访问权限以
lufei
的身份打开文件,然后开始恢复:

$ chmod u=rw resources/views/.user.blade.php.swp
$ vim -r resources/views/.user.blade.php.swp

这可能是由于编辑会话崩溃造成的,如命令
sudo vim market/resources/views/user.blade.php
中的项目2。它使swp文件成为原始文件路径。注意,我实际上没有
/root/market/resources/views/user.blade.php
文件,甚至没有
/root/market/
路径。这是我第一次创建文件
user.blade.php
而不保存它,然后关闭计算机

E325: ATTENTION
Found a swap file by the name "resources/views/.user.blade.php.swp"
          owned by: root   dated: Thu Nov  9 17:33:23 2017
         file name: ~root/market/resources/views/user.blade.php
          modified: YES
         user name: root   host name: localhost
        process ID: 128985
While opening file "resources/views/user.blade.php"

(1) Another program may be editing the same file.  If this is the case,
    be careful not to end up with two different instances of the same
    file when making changes.  Quit, or continue with caution.
(2) An edit session for this file crashed.
    If this is the case, use ":recover" or "vim -r resources/views/user.blade.php"
    to recover the changes (see ":help recovery").
    If you did this already, delete the swap file "resources/views/.user.blade.php.swp"
    to avoid this message.

Swap file "resources/views/.user.blade.php.swp" already exists!
[O]pen Read-Only, (E)dit anyway, (R)ecover, (D)elete it, (Q)uit, (A)bort: 
解决方案:

  • sudo vim market/resources/views/user.blade.php
    ,如果vim显示上述信息,只需按R键,然后保存文件。如果未显示上述信息,请使用
    :rec(over)
    ,然后保存该文件
  • 使用vim打开任何文件env创建一个新文件,使用
    sudo vim aaa.txt
    ,然后使用
    :rec(over)user.blade.php
    ,然后保存它。这将把文件保存到user.blade.php而不是aaa.txt。确保aaa.txt和.user.blade.php位于同一目录中

我尝试过sudo,甚至是root用户。什么都不管用。