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'
6

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

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.