7

I get E303 (Unable to open swap file for "{filename}", recovery impossible) when I open a file in vim in my Ubuntu system.

I see that the backupdir and directory environment variables are set correctly in vim -

:se backupdir

backupdir=~/tools/Vim_Files/vim_backup

:se directory

directory=~/tools/Vim_Files/vim_backup

This is the output of ls -l in the shell -
ls -l ~/tools/Vim_Files/

drwxrwxr-x 2 me me 4096 Oct 12 17:02 vim_backup

This is the relevant portion of my .vimrc setting up these variables -

se nobackup writebackup
let s:vim_cstmztn_files_dir='~/tools/Vim_Files/'   
let &directory=s:vim_cstmztn_files_dir.'vim_backup'
let &backupdir=s:vim_cstmztn_files_dir.'vim_backup'
7

Vim does not interpolate the ~ when using the let & syntax. You must do this manually using expand().

se nobackup writebackup
let s:vim_cstmztn_files_dir=expand('~/tools/Vim_Files/')
let &directory=s:vim_cstmztn_files_dir.'vim_backup'
let &backupdir=s:vim_cstmztn_files_dir.'vim_backup'
0
0

Also, make sure that your disk in not full. This error can also occur when there are no more free disk space to create swap file.

1
0

I had this issue when there was a space after the path of the swap file directory.

backupdir=~/tools/Vim_Files/vim_backup"     "
1
  • 1
    Welcome to Vi and Vim! I edited your post to use code-formatting. I assumed the quotes were just there to indicate the spaces? If so, you might want to edit and indicate that. Also, "I have this problem too" is generally a poor answer—a better answer would state "This is how I fixed it when I had this problem." You can also edit to add such details.
    – D. Ben Knoble
    Jul 6 at 15:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.