使用VIM保存文件时会怎样? [英] What happens when I save a file using VIM?

查看:167
本文介绍了使用VIM保存文件时会怎样?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用了一些文件系统更改,使notify lib监视目录/asdf,并在asdf内部,我vim tmp进行了一些更改,然后使用:wq保存文件

I used some filesystem changing notify lib to watch the directory /asdf, and inside the asdf, I vim tmp, and made some changes and then use :wq to save the file

然后我得到以下输出:

/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之后到底会发生什么?

what is 4913 file? what is tmp~ file? what exactly happens after :wq ?

推荐答案

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

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

An interesting case was mentioned: Neo/Vim creates a temporary file to check if a directory is writable and see the resulting ACL.

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

So, if you’re writing software that watches for file changes, you’ll find Vim creates and deletes file 4913 on almost every edit. ref

其他详细信息 https://groups.google.com/forum/#!topic/vim_dev/sppdpElxY44
https://vi.stackexchange.com/questions/4038/为什么在vim中设置不兼容的结果以节省额外的所有数字临时fi

Additional details 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);

这篇关于使用VIM保存文件时会怎样?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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