Solution of Vim E303 Error under Win 7

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/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值