Vim:如果内容不同,则仅显示 “file has been changed” 警告

标签 vim

是否可以设置 Vim 使其仅显示:

WARNING: The file has been changed since reading it!!!

如果文件实际上不同,而不仅仅是时间戳更改时?

例如,我会经常后台 Vim (^Z),回滚到文件的旧版本(例如,针对它运行测试套件),恢复到当前版本和 fg Vim 再次......但我仍然收到“文件已更改”警告,因为即使内容相同,时间戳也已更改。

最佳答案

如果您尝试使用 vim 7.3
:help timestamp
据说When Vim notices the timestamp of a file has changed, and the file is being edited in a buffer but has not changed, Vim checks if the contents of the file is equal. This is done by reading the file again (into a hidden buffer, which is immediately deleted again) and comparing the text. If the text is equal, you will get no warning.
所以我猜在你的情况下,除了文件时间戳(或者 Vim 中有一个错误)之外,其他东西已经改变了。

就我而言,当我 checkout 文件时,我经常收到这样的消息:即使它们的内容没有改变,它们也会从“只读”变为“读写”。

所以我猜如果文件的属性受到影响,即使内容相同,它也会被视为“更改”。

关于Vim:如果内容不同,则仅显示 “file has been changed” 警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4300253/

相关文章:

regex - 查找距离方差为零且记录瓦数的条目

regex - Vim:我如何搜索后面没有另一个词的词?

javascript - 在 node.js 中编写一个 git post-commit 文件

vim - .vimrc中的条件颜色方案

python - 在 vim 脚本中将创建/修改时间添加到 python 模板

vim - Vim 如何如此快地打开大文件?

vim - 如何在Vim中删除每行末尾的换行符?

vim - 如何在VIM中切换到REPLACE模式

vim - ultisnips 在 Vim 中给我一条错误消息 : E117: Unknown function: UltiSnips#

vim - Vim 效率低下