【问题标题】:What happens when I save a file using VIM? [closed]当我使用 VIM 保存文件时会发生什么? [关闭]
【发布时间】:2017-01-25 03:20:30
【问题描述】:

我使用了一些文件系统更改通知库来查看目录/asdf,在asdf内部,我vim tmp,并进行了一些更改,然后使用:wq保存文件

然后我得到了这个输出:

/asdf/4913 at watch.pl line 9.
/asdf/4913 at watch.pl line 9.
/asdf/tmp at watch.pl line 9.
/asdf/tmp at watch.pl line 9.
/asdf/tmp at watch.pl line 9.
/asdf/tmp~ at watch.pl line 9.
/asdf/tmp~ at watch.pl line 9.

什么是4913文件?什么是 tmp~ 文件? :wq 之后到底发生了什么?

【问题讨论】:

  • 这个网站是关于编程问题的。我不认为询问编辑器 X 的内部工作是这样的。
  • 试着在vi.stackexchange.com问这个
  • 所有自尊的观察者都会做一些事情来处理 Vim 的“怪异”写作行为。如果你的观察者没有,你应该寻找另一个。

标签: linux file vim filesystems


【解决方案1】:

来自https://github.com/neovim/neovim/issues/3460

提到了一个有趣的案例:Neo/Vim 创建了一个临时文件来检查目录是否可写并查看生成的 ACL。

因此,如果您正在编写监视文件更改的软件,您会发现 Vim 几乎在每次编辑时都会创建和删除文件 4913。参考

其他细节 https://groups.google.com/forum/#!topic/vim_dev/sppdpElxY44
https://vi.stackexchange.com/questions/4038/why-does-set-nocompatible-result-in-vim-saving-extra-all-numeric-temporary-fi

这是导致此问题的代码

/*
 * Check if we can create a file and set the owner/group to
 * the ones from the original file.
 * First find a file name that doesn't exist yet (use some
 * arbitrary numbers).
 */
STRCPY(IObuff, fname);
for (i = 4913; ; i += 123)
{
    sprintf((char *)gettail(IObuff), "%d", i);
    if (mch_lstat((char *)IObuff, &st) < 0)
        break;
}
fd = mch_open((char *)IObuff,
                O_CREAT|O_WRONLY|O_EXCL|O_NOFOLLOW, perm);
if (fd < 0)     /* can't write in directory */
    backup_copy = TRUE;
else
{

    ignored = fchown(fd, st_old.st_uid, st_old.st_gid);
    if (mch_stat((char *)IObuff, &st) < 0
        || st.st_uid != st_old.st_uid
        || st.st_gid != st_old.st_gid
        || (long)st.st_mode != perm)
    backup_copy = TRUE;
    /* Close the file before removing it, on MS-Windows we
     * can't delete an open file. */
    close(fd);
    mch_remove(IObuff);

【讨论】:

猜你喜欢
  • 1970-01-01
  • 2014-12-20
  • 1970-01-01
  • 1970-01-01
  • 2015-06-30
  • 2020-05-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多