Cannot create backup file(add ! to overwrite)

人盡茶涼 提交于 2020-08-22 02:39:50

问题


Need help. I have been editing a text file in vi , and i was able to save the changes before but now i am getting the above error whenever i am typing command to save the file. Please help .


回答1:


You can, as vi (or, more likely, vim) is saying force a write by doing:

:w!

Alternatively, write the file to an alternative location:

:w! /path/to/other/location

To check where your backup files are being written (normally):

:se backup? backupdir? backupext? 

Try to touch a file in that directory and see if your Operating System gives you an error to enlighten you as to why your editor cannot write there.




回答2:


Had the same problem. It was because I installed vimconf as root. You need to change rights of files in ~/.vim directory and change owner to your user.

sudo chmod 0750 ~/.vim
sudo chown user ~/.vim



回答3:


Had the same problem. Tried all options as above but it did not work. Then when I checked my disk space, it was full. Once I cleared some space then I was able to write back to file again.
P.S: This was in linux.




回答4:


I had this same problem. Turns out it was due to running out of disk space. try creating a file using Ex) touch test.txt. If you get a message saying touch: cannot touch test.txt: No space left on device you will need to clear up space on your disk




回答5:


I've fixed this with:

sudo chown {user} ~/.cache/vim/* -R 

where the "{user}" field is your user-name.




回答6:


I don't know what the cause was, but I moved by backupdir from . to ~/.vim/backups in my .vimrc and it solved it for me:

set backupdir=~/.vim/backups

I'd imagine some sort of tool was using the folder the file I was editing it in (Visual Studio 2013, in my case), but I'm not sure.




回答7:


from within vi, try:

:w!

:help w! gives the following information:

                                                       *:w!*
:[range]w[rite]! [++opt] {file}
                        Write the specified lines to {file}.  Overwrite an
                        existing file.



回答8:


Another possibility is that you put your backups in a centralized location (e.g. /tmp) and you edited a particular file as root. Then, the backup file will be owned by root and un-writeable by you as a mere mortal later.

In this case, the suggestion above to touch /tmp/atestfile won't show the problem! You'll have write permissions, no problem, but not to the particular backup file vim is trying to write.

Remove the file as root (sudo rm).

Note that the reason w! works is because vim writes the file without writing a backup file (you're insisting that it write despite the error).




回答9:


In my case my disk was full.

Here are some commands to verify this and find where the disk space is being taken. In my case it was the PHP log at over 20GB.

# see general disk space usage
df -h

# see current file and directory disk space usage. You can go to / and work your way in
du -sh *



回答10:


Backup location can be given in .vimrc, e.g.:

set backupdir=~/.vim/backup

You may need to create this directory yourself.



来源:https://stackoverflow.com/questions/8428210/cannot-create-backup-fileadd-to-overwrite

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!