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 .
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.
~/.vim/backups
) didn't exist. I created it, and the error went away. –
Baskerville :se backup? backupdir? backupext?
! ---- In my case the subdirectory backup
(as specified by the backupdir
option value) was missing along with my plugins from a corrupted ~/.vim/
directory. –
Sazerac sudo chown -R peng:peng ~/.vim*
–
Albumen set backupdir=$PATH
, and $PATH
does not exist. –
Neogaea :echo join(['ls ',strcharpart(expand('%'),0,strcharlen(expand('%'))-1),'?','backupext],'')
–
Expellant 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
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.
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
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.
I've fixed this with:
sudo chown {user} ~/.cache/vim/* -R
where the "{user}" field is your user-name.
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.
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 *
Backup location can be given in .vimrc
, e.g.:
set backupdir=~/.vim/backup
You may need to create this directory yourself.
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).
I just started using nvim and I found my issue was that my borrowed premade vimrc file had a preset source in it.
grep -rnw ~/.config/nvim/ -e backup
.config/nvim/lua/custom/vimrc:132:set backupdir=~/.backup/,/tmp/
Like others here, creating that backup directory cleared my error message (~/.backup/)
I think it's also worth mentioning that the problem might not be the permissions you have in the backup directory. For me the file I was writing was in a root owned directory, although the file was user owned.
This massage might appear if you are editing a file that is not owned by you, i.e. you are editing a file in a directory owned by root.
you can use this command in the directory to see what is owned by you and what is owned by root.
~/test λ ls -la .
total 8
drwxr-xr-x 2 root root 4096 Jul 20 01:50 .
drwx------ 27 root root 4096 Jul 20 01:49 ..
-rw-r--r-- 1 user user 0 Jul 20 01:50 hello
in this case hello file is owned by user but the directory .
is owned by root. if you tried to edit the file and save with vim or neovim, it will display error Can't write to backup file (add ! to override)
.
so to solve this you can
sudo chown root:root hello
sudo vim hello
and it should work as expected.
Simple first free some space and try again..if still same issue then try to save with :w!
© 2022 - 2024 — McMap. All rights reserved.