How to open a new file in gvim? E303: Unable to open swap file

7,183

Solution 1

This seem to be a bug. From Vim E303: Unable to open swap file for "[No Name]", recovery impossible, I should add this to _gvimrc:

set directory=.,$TEMP

Solution 2

To clarify the location of files and directories, which aren't immediately obvious, here is another solution.

Make the following directories (e.g., from a command prompt):

mkdir %HOMEPATH%\vim\backup
mkdir %HOMEPATH%\vim\tmp

Note that %HOMEPATH% equals C:\Users\User.Name, where "User.Name" is your Windows user name.

Then copy the following into %HOMEPATH%\_vimrc:

set backup
set backupdir=$HOME\vim\backup
set directory=$HOME\vim\tmp
set nosmartindent
set tabstop=2
set shiftwidth=2
set expandtab
set ai
set pastetoggle=<F2>
syntax on

Save the file and the error should go away.

Share:
7,183
Jonas
Author by

Jonas

I'm a Computer Science student.

Updated on September 18, 2022

Comments

  • Jonas
    Jonas over 1 year

    I use gvim on Windows. How can I open a new file?

    I have tried with :e ~\mypath\myfile.txt but I get this error message:

    E303: Unable to open swap file for "C:\Users\Jonas\mypath\myfile.txt", recovery impossible

    How to open a new file using gvim on Windows?

  • Gavin Smith
    Gavin Smith about 10 years
    Thanks! Using the environmental variable TEMP seems the best way to go, yet so few people suggest it from what I've seen.
  • Kasper van den Berg
    Kasper van den Berg over 7 years
    Note that the second solution has side effects: it set formatting and indentation behaviour, syntax highlighting, and will always make a backup when you write a file.