A top notch file backup mechanism for Vim. Maintain copies of your files, anywhere, and never lose anything again.
- Work in Vim as you normally would.
- Save your file.
- vim-git-backup does everything else for you, in the background.
Because the file back ups happen using git, any tool which uses git as a backend can be used to view or edit your backups.
Here's a few personal favorites
Control the folder where backups are stored, either by setting the
VIM_CUSTOM_BACKUP_DIRECTORY
environment variable or by setting g:custom_backup_dir
in your .vimrc.
e.g.
export VIM_CUSTOM_BACKUP_DIRECTORY=~/some/folder
let g:custom_backup_dir = "~/some/folder"
By default, :GHistory's file list is in the order of most-recently-updated. This calculation is a bit slow. If you want it faster and don't care about file order, or just want file lists to be alphabetical, use this:
let g:git_backup_keep_file_order = 0
If you've ever wanted to do any of the following things, you will love this plugin:
- Show the most recently edited files
- See all changes from the previous revision
- Diff the changes in the last week
- Get a list of all changed files from the last X days
- Get the all-time diff of the files in the current directory
- Search for any text which you A. Don't remember what file you put it in B. Was deleted a while ago
- Search for git commits which contain a phrase through EVERY revision of every file in the current directory
- Get the search contents for each commit that contains a phrase through EVERY revision of every file in the current directory
- Backup any file as it was, X days ago
- Restore a previous version of a file
- View your backups using a tool like agit or fugitive
- Get a summary of what you've worked on over X days (for time-keeping purposes)
And did I mention, each scenario above applies both to "overall" but also can be filtered using the current directory?
This simple plugin easily provides all of this functionality and more. Interested? Read on!
So you've installed vim-git-backup and have a catalog of back-ups that you want to start using. Great!
To summarize, you can use any git command to construct your own queries, like this:
git -C ~/.vim_custom_backups grep foo # Search for "foo" across all commits and all files
git -C ~/.vim_custom_backups log # Get all commit history for your backups
Personally, I find writing all that to be tedious so I wrote a really simple wrapper script to do make it easier to write.
With the wrapper, you can now do things like
ghistory grep -n foo -- . # Search in the current directory for any commit containing "foo"
ghistry log -Sblah -- . # Search log contents for "blah"
ghistory CHANGED # Show every tracked file, in "date modified" order
ghistory CHANGED -- . # Show every tracked file, in "date modified" order, of the current directory
The wrapper script has a many different example commands. The few above are just a fraction of what's possible.
Beyond the automatic functionality of vim-git-backup, there's also some helpful functions which you can call to view and restore back up files. To learn more, run this while inside Vim:
:help vim-git-backup
:help vim-git-backup-advanced-commands
- Vim 8.0+
- Linux (Windows support on-request)
This plugin idea came from this post