当vim使用swp文件

时间:2017-11-10 02:52:32

标签: file vim

我想要恢复/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:无法打开资源/ views / .user.blade.php.swp按ENTER或   键入命令继续

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

  

“/根/市场/资源/视图/ user.blade.php”
  “/root/market/resources/views/user.blade.php”E212:无法打开文件   写入按ENTER或键入命令继续

从上面的信息我认为vim想要将文件保存到根目录。从vi - getting an error E212: Can't open file for writing开始,我想如果我创建路径/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

从上面尝试,无论我使用普通用户还是root用户,当我恢复文件时,vim会尝试将文件保存到路径不存在的错误位置。

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

2 个答案:

答案 0 :(得分:1)

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

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

答案 1 :(得分:0)

这可能是由编辑会话压缩引起的,如命令sudo vim market/resources/views/user.blade.php中的项目2。它使swp文件成为wong原始文件路径。注意我甚至没有/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: 

解决方案:

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