1

:autoread在vim中使用netrw访问远程文件时有什么等价物吗?

我通过 netrw 远程访问我的工作机器上的文件,然后在我上班时修改那里的文件。但是,如果我回到远程访问,如果文件已经在缓冲区中打开,很容易忘记重新加载文件 - 如果它已在工作机器上修改,那么下一个:w将覆盖我在工作。我正在寻找一个“安全网”来降低数据丢失的风险(幸运的是,我还没有因为.swp文件丢失任何东西,但这不是一个非常令人放心的网络)。

4

2 回答 2

1

你试过了:checktime吗?

        Check if any buffers were changed outside of Vim.
        This checks and warns you if you would end up with two
        versions of a file.
        [...]
        Each loaded buffer is checked for its associated file
        being changed.  If the file was changed Vim will take
        action.  If there are no changes in the buffer and
        'autoread' is set, the buffer is reloaded.  Otherwise,
        you are offered the choice of reloading the file. 
于 2013-06-25T03:43:44.670 回答
1

使用'autoread',Vim 只需要检查文件修改时间。由于netrw目标驻留在不同的系统上,因此查找成本最高,您必须自己触发它。一个想法是对FocusGained事件进行检查,即当你回到你的(家用机器的)Vim 时。由于在 Windows GVIM 上,netrw 访问会弹出一个控制台窗口(触发另一个FocusGained),为了避免过于频繁的检查,让我们将检查限制在一定的时间间隔内,例如最多每 5 分钟一次:

:autocmd FocusGained ftp://*,scp://* nested
\   if ! &modified && ! exists('b:lastchecktime') || localtime() - b:lastchecktime > 300 |
\       edit! |
\       let b:lastchecktime = localtime() |
\   endif
于 2013-03-27T07:57:08.463 回答