vim - 自定义 Vim 写入功能以制作备份副本
问题描述
我想在 Vim 中创建一个 write 函数,它执行以下操作:
- 在文件被编辑之前将文件复制到一个目录(让我们称之为 back_up_before_last_change)
- 将新的编辑写入当前文件
- 将更新的文件复制到一个目录(让我们称之为back_up)
这样我可以查看较旧的更改,如果文件被意外删除,我将始终拥有最新的备份。有谁知道如何做到这一点或向我推荐一些资源,以便我自己弄清楚。谢谢
解决方案
I would highly recommend some form of version control, like git or mercurial. This will give you the file history that you want (bonus: branching) and will also provide easy way to clone and share history between different repositories.
Git
You can use a plugin like vim-futitive to handle staging, commits, and many other git functions. Vimcasts provides some a nice screencast tutorial for fugitive:
- A complement to command line git
- Working with the git index
- Resolving merge conflicts with vimdiff
- Browsing the git object database
- Exploring the history of a git repository
Persistent Undo
To go along with version control, Vim also provides persistent undo where it save's Vim's undo history to a file. See :h persistent-undo
.
Simply set 'undofile'
in your vimrc
:
set undofile
May want to set 'undodir'
to a different location, e.g. set undodir=~/.local/vim/undo
. Note: 'undodir'
must exist.
It should be noted persistent undo is not version control and should not be treated as such. For example undo history can easily be messed up by editing a file in a different editor.
Plugins like Gundo and undotree may help in navigating deep in the past or complicated undo histories.
推荐阅读
- html - 在弹性列表项之间设置空格
- flutter - 如何为这两个文本设置相同的对齐方式
- c# - 将 Datatable 从一个表单传递到另一个表单 C#
- android - 改造 IlegalStateExecption:关闭和打开请求
- laravel - Laravel - 如何清除每个请求的配置:缓存
- python - Python libusb:缺乏USB访问权限
- sql - 在 bigQuery 上运行的简单查询
- python - LightGBM 不接受我的数据的 dtypes
- c# - 如何使用带有 c# 的 Plaid.NET Nuget 包创建链接令牌
- google-apps-script - 如果范围部分由单元格值形成,则 Google 表格 get.range 语法