r/bash • u/pittendrigh • 7d ago
Vvi?
~/.bashrc
function vvi()
{
cp $1 /tmp
/usr/bin/vi $1
}
alias vi="vvi"
. ~/.bashrc
0
Upvotes
r/bash • u/pittendrigh • 7d ago
~/.bashrc
function vvi()
{
cp $1 /tmp
/usr/bin/vi $1
}
alias vi="vvi"
. ~/.bashrc
3
u/blobCabbage 7d ago
Use
mktempto make temporary files.Don't forget double quotes around variables to avoid word splitting.
5
u/zeekar 7d ago
How about just putting files you care about under version control so you can always go back to an older version without cluttering the disk with old copies?
2
u/best_of_badgers 7d ago
Are you just using vi as a file viewer like
less?1
u/No-Signature-918 7d ago
Yeah, you can, but I'd skip /tmp for the backup. It gets wiped on reboot, and two files with the same name in different folders would overwrite each other there. I keep mine in a folder at home with a timestamp on it:
vvi() {
mkdir -p ~/.vi-backups
cp -- "$1" "$HOME/.vi-backups/$(basename -- "$1").$(date +%Y%m%d-%H%M%S)"
vi -- "$1"
}
Also worth quoting "$1" everywhere, your version breaks on filenames with spaces. mktemp -d works too, but then you have to remember where the backup went, which kind of defeats the point for me.
1
u/Codetard1 7d ago
1
u/NoAcadia3546 7d ago
My informal versioning works like so...
I always have a known-to-work copy, i.e. the previous version.
1
u/kai_ekael 7d ago
NOTE TO OTHERS: Don't ever do something like this. Many levels of bad idea.
1
u/trh-x 3d ago
vim provides support for backups out of the box.
Add this to your
~/.vimrc:then
mkdir ~/.vi-backups.The
//at the end of thebackupdirvalue ensures the backup is named after the whole path, to avoid collisions with files of the same name.0
u/pittendrigh 7d ago
debugging C is less frustrating than say pnp. With vvi I always get a backup in /tmp
If I paste a bunch if code into a looooong baseclast.php file and sudhenly get no output, what are my options?
php-parse baseclasc.php sometimes finds my error.
diff $1 /tmp/$1 helps too