为什么 Vim 用 ~ 扩展名保存文件? [英] Why does Vim save files with a ~ extension?

查看:34
本文介绍了为什么 Vim 用 ~ 扩展名保存文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现在 Windows 上使用 Vim 时,Vim 会保存文件,关闭 Vim 窗口时删除的 .ext.swp 文件和 .ext~文件.

I've found that while using Vim on Windows Vim saves the file, a .ext.swp file that's deleted on closing the Vim window and a .ext~ file.

我假设 .ext.swp 文件是一个会话备份,以防 Vim 崩溃..ext~ 文件的用途是什么?这是永久备份文件吗?这很烦人,因为我想将我正在处理的所有文件复制到我的主机上,而没有这些重复项.如何关闭或(如果有充分的理由)隐藏文件?

I assume the .ext.swp file is a session backup in case Vim crashes. What's the purpose of the .ext~ file however? Is this a permanent backup file? It's annoying as I'd like to copy all the files I'm working on to my host, without these duplicates. How can I turn this off or, if it's there for a good reason, hide the files?

推荐答案

*.ext~ 文件是一个备份文件,包含您编辑之前的文件.

The *.ext~ file is a backup file, containing the file as it was before you edited it.

*.ext.swp 文件是交换文件,它用作锁定文件并包含撤消/重做历史以及 Vim 需要的任何其他内部信息.如果发生崩溃,您可以重新打开您的文件,Vim 将从交换文件中恢复其先前的状态(我觉得这很有帮助,所以我不会将其关闭).

The *.ext.swp file is the swap file, which serves as a lock file and contains the undo/redo history as well as any other internal info Vim needs. In case of a crash you can re-open your file and Vim will restore its previous state from the swap file (which I find helpful, so I don't switch it off).

要关闭自动创建备份文件,请使用(在您的 vimrc 中):

To switch off automatic creation of backup files, use (in your vimrc):

set nobackup
set nowritebackup

其中 nowritebackup 更改默认的保存"Vim 的行为,即:

Where nowritebackup changes the default "save" behavior of Vim, which is:

  1. 将缓冲区写入新文件
  2. 删除原文件
  3. 重命名新文件

并使 Vim 将缓冲区写入原始文件(导致在 I/O 错误的情况下破坏它的风险).但是你可以防止跳转文件"在带有它的 Windows 桌面上,这是我安装 nowritebackup 的主要原因.

and makes Vim write the buffer to the original file (resulting in the risk of destroying it in case of an I/O error). But you prevent "jumping files" on the Windows desktop with it, which is the primary reason for me to have nowritebackup in place.

这篇关于为什么 Vim 用 ~ 扩展名保存文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆