ViM: Unable to open swap file
Problem
|
1
|
E303: Unable to open swap file for "[No Name]", recovery impossible
|
You might see this error while using ViM as a standard user on Windows 7. This is a result of ViM still catching up to being used as a standard user on Windows 7.
By default, ViM opens a swap file when the user starts editing an already existing file. On Windows, the swap file is a hidden dot file named the same as the opened file with a suffix of .swp. For example, editing hello.cpp will create a hidden .hello.cpp.swp. This swap file is created in the same directory as the opened file.
If the user just opened ViM and started editing into the empty editor, what happens? On Windows, a hidden swap file named _.swp is created. The above error is caused because ViM on Windows 7 tries to create this swap file in C:\Windows\System32. A standard user does not have the permissions to create files there and thus ViM throws the E303 error.
Solution
The solution would be to tell ViM to create the swap files in a temporary directory where a standard user has all the necessary permissions. A good location would be the directory pointed to by the %TEMP% environment variable. On Windows 7, this points to C:\Users\AverageJoe\AppData\Local\Temp.
The directory where ViM creates its swap files is read from the dir (or directory) variable. Setting it to %TEMP% solves the above error:
|
1
|
:set dir=$TEMP
|
Note that ViM swap file behaviour changes a bit when the dir variable is set. All swap files are created in this directory, as opposed to being created in the directories of the files being edited. And the swap filenames are not prepended with a dot. For example, editing D:\Work\hello.cpp creates a hidden swap file C:\Users\AverageJoe\AppData\Local\Temp\hello.cpp.swp
reference: http://choorucode.com/2010/01/14/vim-unable-to-open-swap-file/
在Windows7环境下使用Vim编辑器时遇到无法打开swap文件的E303错误,本文提供了解决方案,即通过设置dir变量为%TEMP%,使swap文件在临时目录中创建,从而避免权限问题。
2168

被折叠的 条评论
为什么被折叠?



