After typed vim ~/.ssh/config in terminal, then got error message like picture1
what I did for solving
1.push D in the screen to try to delete swap file.but it looks like pointless
2.push r in the screen to confirm swap file.But I don't know how can I delete them.you can the condition in picture2.
please give me the tip how can I remove the error,
You can delete the swap file as suggested
rm /Users/snowman/.ssh/.config.swp
in case you edited the file using a different user (so you have no permission to delete the file) try
sudo rm /Users/snowman/.ssh/.config.swp
You can use rm as suggested by others including the answer from #Arsenio.
As you have multiple have files, you need to delete them one by one, of course
after recovering from the copy that you want.
\rm ~snowman/.ssh/.config.sw*
But newer version of vim, It is easier than rm and you already have newer version of vim which supports that.
New version of vim will have (D)elete it option. So you can
(R)ecover
followed by
:e!
At this point, we will have the same screen with (D)elete it. Now you can safely press D
Use
vim -r filename
and then there will be an option to delete the swap file.
Related
I feel like I've literally tried everything, but no matter what I add to vimrc, I can't get it to store its annoying .swp files in /tmp. I'm using Ubuntu 16.04. I've obviously looked up this issue extensively, but again, no command I enter seems to work. I always end up with:
E510: Can't make backup file
(add ! to override)
Things I've tried:
set backupdir=$~/tmp//
set directory=$~/tmp//
set backupdir=~/tmp//
set backupdir=$HOME~/tmp//
set backupdir=/tmp//
I mean you name it, I've tried it. So, explicitly, what is the exact code I need to type in vimrc to make it so vim saves it's .swp files in my temporary folder, instead of cluttering my workspace?
Thank you.
Adding the following line to my ~/.vimrc puts .swp files for currently open buffers under /tmp
set directory=/tmp
If you've tried this without issues are you able to verify that vim is reading your vimrc at all?
It appears the issue was I didn't really understand what ~ means. I created a folder called 'tmp' in my home directory, and from there used:
set backupdir=~/tmp//
I have modified the .vimrc file in my user. The settings dont work when i switch to superuser.
When i check the contents of the file (using vim editor) i can see the mapped keystrokes of newlines
(with all the text extending on the rightside beyond screen on same line), but when i check the contents of .vimrc as root, i see all the text in the same window screen one below the other (this may be a very stupid difference, but that is the only difference i noticed. all the data in the file is same).
i am unable to understand what is wrong and how can i correct it.
root is a user too, when you start vim with root, vim load the root's Home/.vimrc usually it is /root/.vimrc
You can cp or ln -s your user's vimrc to /root if this is a personal desktop machine.
I hope I understood your problem.
You did not state a precise question, so for the sake of completeness :
If what you want is being able to modify files as root using your user's vim and .vimrc, you can do
sudo -e /path/to/your/file
sudo will use the editor configured in $EDITOR as the current user, to edit a temporary copy of the file that will get copied over when you write the file.
The caveat is that you will not be able to have any edition history between sessions. For example, if you modify /etc/group once, save the changes and quit, and then reopen the file again, you will not be able to undo the modification you did at first.
For Neovim users, you can do what comes next:
If your root user settings for neovim are important, make a
backup for those dotfiles.
Create a symbolic link from your default user to /root/.config directory.
sudo mv /root/.config/nvim /root/.config/nvim.bkp; sudo ln -s $HOME/.config/nvim /root/.config/
Be aware that some plugins may need some files that are not under
.config/nvim directory.
On Debian GNU/Linux there is also a shared configuration file in /usr/share/vim/vimrc. (Actually this is a soft link to /etc/vim/vimrc.) See the bottom of the man page on vim.
I want my app to update automatically when I save my files. So I use inotify (ubuntu) to create watchers that detect the events.
The issue is vim overwrites the file instead of updating it. So my watcher is lost after the first update.
I wonder, is there a way to setup vim so it doesn't use swap files and updates directly the file ?
(I tried :set noswapfile and the -n option, that removes the swap file without changing the behaviour)
You can do this:
:set backupcopy=yes
With Vim, you can control this via the 'backupcopy' setting; however, I once took an alternative route and monitored the directories, not the files themselves:
inotifywait --quiet --monitor --event modify --format '%w%f' "$dir"
This required some more processing in my script (checking whether the modified file matches my list), but also enabled me to capture newly created files, too.
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.
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.
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
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 tried to pull some changes while I had some files opened in vim, and while committing and merging and the sort, ended up coming up with:
alex#adebian:~/cs4290/p3$ hg status
R test
! project3_framework/protocols/.MI_protocol.cpp.swp
! project3_framework/protocols/.MSI_protocol.cpp.swp
I added a .hgignore file in my project with the following:
syntax: glob
*.cpp.swp
I've since closed my vim session (removing the files) yet the files keep showing up. How do I get mercurail to ignore the .swp files?
! sign means that mercurial cannot find the file that has been already added to the repository. So you need to forget or remove those files at first. After that - they will not appear anymore in the status since you have ignored them.
I agree with zerkms... forget or remove those files to get rid of the !. Also, as you've probably noticed, simply creating a .hgignore file with some content does not go through the repository and remove matching files. If you've added foo.c to your project and then you create the following .hgignore:
syntax: glob
*.c
foo.c will still be a part of the project - you would need to remove it explicitly.
You can use
set directory=c:\\workfiles\\
in your .vimrc to write swap files in a "special" folder