linux中vim中swapfile,在vim中撤消从交换文件恢复(Undo recovery from swap file in vim)

在vim中撤消从交换文件恢复(Undo recovery from swap file in vim)

在进行重大更改之前,我无意中在vim中从旧的和过时的交换文件“恢复”了该文件。 我的改变似乎没有了。 我试图探索撤消树,但仍然缺少大块的变化。 无论如何,我可以撤销恢复行动,还是注定了?

Right before committing a major change, I accidentally "recovered" the file from an old and outdated swap file in vim. My changes seem to be gone. I've tried exploring the undo tree but large chunks of changes are still missing. Is there anyway I can undo the recover operation or am I doomed?

原文:https://stackoverflow.com/questions/21385956

更新时间:2019-06-05 15:12

最满意答案

我只是自己尝试过(启用了持久性撤销; Vim 7.3.823版)。 旧的变化仍然显示出来(in :undolist ,虽然我通常使用像Gundo或Undotree这样的插件来可视化它),但是当尝试恢复时,我得到

E438: u_undo: line numbers wrong

似乎Vim无法处理这种情况。 请注意,您已被警告; 经济复苏明确警告说:

Recovery completed. You should check if everything is OK.

E308: Warning: Original file may have been changed

I just tried this myself (with persistent undo enabled; Vim version 7.3.823). The old changes were still showing (in :undolist, though I usually use a plugin like Gundo or Undotree to visualize it), but when attempting to restore, I get

E438: u_undo: line numbers wrong

Seems like Vim cannot handle this situation. Note that you've been warned; the recovery explictly warns:

Recovery completed. You should check if everything is OK.

E308: Warning: Original file may have been changed

2014-01-27

相关问答

我只是自己尝试过(启用了持久性撤销; Vim 7.3.823版)。 旧的变化仍然显示出来(in :undolist ,虽然我通常使用像Gundo或Undotree这样的插件来可视化它),但是当尝试恢复时,我得到 E438: u_undo: line numbers wrong

似乎Vim无法处理这种情况。 请注意,您已被警告; 经济复苏明确警告说: Recovery completed. You should check if everything is OK.

E308: Warning: O

...

我可以想到的两种方法。 有了Vim,可能会更多! :33 | delete | 15 | put | 15 | delete | 32 | put

...要么... 13ggdd15ggPjdd33ggP

...击键次数较少,但写下时不易理解! Two ways I can think of. With Vim there are probably more! :33 | delete | 15 | put | 15 | delete | 32 | put

...or... 13ggdd15

...

看起来你有一个开放的git commit或git merge ,编辑器仍然打开编辑提交消息。 两个选择: 查找会话并完成(最好)。 删除.swp文件(如果您确定其他git会话已经消失)。 Looks like you have an open git commit or git merge going on, and an editor is still open editing the commit message. Two choices: Find the session and finis

...

我有vim存储我的交换文件在一个本地目录,通过在我的.vimrc: set directory=~/.vim/swap,.

除了其他好处,这使得交换文件容易一下子找到。 现在当我的笔记本电脑失去电源或任何东西,我开始备份一堆交换文件,我只是运行我的cleanswap脚本: TMPDIR=$(mktemp -d) || exit 1

RECTXT="$TMPDIR/vim.recovery.$USER.txt"

RECFN="$TMPDIR/vim.recovery.$USER.fn"

trap

...

我在我的.vimrc有这个,它的命名交换文件具有完整的路径名和百分号,正如你所描述的: " Store swap files in fixed location, not current directory.

set dir=~/.vimswap//,/var/tmp//,/tmp//,.

关键是//在目录的末尾。 请参阅本说明:help dir : 对于Unix和Win32,如果一个目录以两个路径分隔符"//"或"\\"结尾,那么交换文件名将从文件的完整路径构建,所有路径分隔符都被替换为百分比

...

如果您的文件可以包含注释,则可以通过在文件的开头或结尾添加模式行来设置nobackup和noswap文件。 像这样的东西: # vim: set nobackup noswapfile:

If your file can contain comments you can set the nobackup and noswapfile by adding a modeline to the start or end of the file. Something like this: # vim:

...

把它放在你的.vimrc中: set noswapfile

编辑:您还可以考虑将备份文件移动到不会妨碍您的位置。 我在.vimrc中有这个: set noswapfile

" Alternatively, store your swap files in your local .vim folder

" call system('mkdir ~/.vim/swap')

" set dir=~/.vim/swap/

if has('persistent_undo')

set undoleve

...

删除交换文件会消除警告: rm ~/Desktop/code/web/.git/.COMMIT_EDITMSG.swp

Deleting the swap file gets rid of the warning: rm ~/Desktop/code/web/.git/.COMMIT_EDITMSG.swp

Darn, okay. Is there a setting I could turn on to enable automatic writes

to a swap file on each change?

阅读:h swap ,特别如下: 更新交换文件〜 输入200个字符后或者在4秒钟内没有输入任何内容时,交换文件会更新。 这只发生在缓冲区被改变时,而不是当你只是移动时。 它不能一直保持最新状态的原因是这会使正常工作减慢太多。 您可以使用'updatecount'选项更改200个字符数。

...

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值