VIM save options to protect file from too easy delete?
Hi,
I am looking for a save option in VIM (not crazy high level), just something simple that keeps me from easily deleting a file I have created. For instance, if I save file 'test' in VIM all I have to do to delete it is ' rm test '. How can I save file 'test' so that simply typing ' rm test ' does not delete the file forever? Some suggestions on other non VIM methods for protecting files are welcome. But the main idea here is something not extreme. Something simple and low level. Over the post month I have been relearning Linux and managed to accidentally delete some longish C programming files that I had to retype out. I want there to be an option in VIM that saves a file so that it asks me before deleting. Thank you, Jon. |
Keep the files in a Git repo, and get Vim to auto-commit whenever you save.
Here's a result from a relevant search that provides a few solutions: https://superuser.com/questions/286290/is-there-any-way-to-hook-saving-in-vim-up-to-commiting-in-git |
Quote:
. . . BUT again what I am really really looking for is something native to VIM that can quickly easily save a file into some semi-protected state. If there not that sort of thing then OH WELL bummer. Just seems like there should be. ' rm file ' and its gone forever is really pathetic. Again thank you for your reply. |
This isn't a Vim problem - you're the one typing "rm file" - don't use rm and you've not got the problem.
https://duckduckgo.com/?q=linux+prev...ental+deletion Quote:
Using Git is a simple way to solve this problem and others. |
Quote:
http://stevenrosenberg.net/blog/appl...from_within_vi It does, of course, need you to understand how nix file permissions work. |
Quote:
What I have done is just create directory Trash in /home/me and from now on will just move files to there that I think I am probably done with. Right now I am trying to figure out how to create a command 'mvt' that automatically moves a file to ~/Trash without me having to type ~/Trash. Thing with me is (coming from Windows) I will quite often delete files that I am only mostly sure I want gone, usually as a 'tidying up' measure and I just like that short term option of going "ohh wait, I actually still want that file." I usually go two weeks before emptying Recycle Bin. I realize Linux desktops also have this but when I am in Linux I almost never use GUI. So how would I create a custom command 'mvt' that automatically moves 'trash' files to directory ~/Trash ? That is my next Linux learning project. |
I'd suggest to alias rm in your shell to
Code:
rm -i |
Quote:
https://apple.stackexchange.com/ques...-the-trash-can What I am now really wanting to do now is create a custom command ' mvt ' that automatically moves files to ~/Trash I have created a Trash directory in my /home/me and of course I can use 'mv file1 file2 ~/Trash' but for Linux learning purposes I would like to create a custom command where no matter what directory I am in I can just type -$ mvt file1 file2 , and it automatically moves them to ~/Trash Any suggestions? |
Quote:
|
Quote:
Ha! Check this out. Earlier I inquired about this of Joe Collins of youtube in a comment on one of his videos and already he made this reply video answering my question. This guy is amazing! This is a somewhat different solution than to what I inquired about in my original post here but satisfies the general spirit of it. BASH Script to put Files In the Trash |
Quote:
|
Quote:
Anyway I found a good solution: Below is a script command I named 'mvt' that can be used thus: -$ mvt file1 file2 This command 'mvt' moves files to a folder called Trash in Home directory, and creates the folder if it is not there already. HERE IS THE SCRIPT. Note once created it will need to have 'chmod +x' applied to it remove 'permission denied' error. I have mine in /bin WITHOUT the .sh file extension Code:
|
Quote:
|
Quote:
Don't believe everything you read on the internet. |
All times are GMT -5. The time now is 03:49 AM. |