当您在 vim 中编辑文件时,它会生成一个与当前文件同名的交换文件,但带有.swp
扩展名。
如果.swp
已经被占用,那么它会一对一地生成.swo
。如果已经被占用,那么你会得到.swa
等等。
我找不到任何有关这些文件的确切命名回退顺序的文档,任何人都可以澄清按照什么约定选择扩展名吗?
答案1
太长了;博士 swp
, swo
, ..., swa
, svz
, svy
, ..., sva
, ..., saa
。到达最后一个时,它会触发错误。
您正在寻找(和注释)的特定代码段位于memline.c
:
/*
* Change the ".swp" extension to find another file that can be used.
* First decrement the last char: ".swo", ".swn", etc.
* If that still isn't enough decrement the last but one char: ".svz"
* Can happen when editing many "No Name" buffers.
*/
if (fname[n - 1] == 'a') /* ".s?a" */
{
if (fname[n - 2] == 'a') /* ".saa": tried enough, give up */
{
EMSG(_("E326: Too many swap files found"));
vim_free(fname);
fname = NULL;
break;
}
--fname[n - 2]; /* ".svz", ".suz", etc. */
fname[n - 1] = 'z' + 1;
}
--fname[n - 1]; /* ".swo", ".swn", etc. */
答案2
代码片段中的信息是在 Vim 的帮助下。看:h swap-file
:
The name of the swap file is normally the same as the file you are editing,
with the extension ".swp".
- On Unix, a '.' is prepended to swap file names in the same directory as the
edited file. This avoids that the swap file shows up in a directory
listing.
- On MS-DOS machines and when the 'shortname' option is on, any '.' in the
original file name is replaced with '_'.
- If this file already exists (e.g., when you are recovering from a crash) a
warning is given and another extension is used, ".swo", ".swn", etc.
- An existing file will never be overwritten.
- The swap file is deleted as soon as Vim stops editing the file.
Technical: The replacement of '.' with '_' is done to avoid problems with
MS-DOS compatible filesystems (e.g., crossdos, multidos). If Vim
is able to detect that the file is on an MS-DOS-like filesystem, a
flag is set that has the same effect as the 'shortname' option.
This flag is reset when you start editing another file.
*E326*
If the ".swp" file name already exists, the last character is
decremented until there is no file with that name or ".saa" is
reached. In the last case, no swap file is created.
答案3
在,稍微容易一些的眼睛,正则表达式说话:
[._]*.s[a-v][a-z]
[._]*.sw[a-p]
[._]s[a-v][a-z]
[._]sw[a-p]
其来源是 Github 自己的 gitignore 文件维姆。
答案4
这个 .gitignore 替代方案应该让每个人都满意。第二行否定忽略“*.swf”。
*.sw[a-p]
!*.swf