Vim:所有可能的交换文件扩展名是什么?

New*_*ewb 32 vim filenames

当您在 vim 中编辑文件时,它会生成一个与当前文件同名但带有.swp扩展名的交换文件。

如果.swp已经被占用,那么它会生成一个.swo一个。如果这已经被采用,那么你会得到.swa,等等。

我找不到任何关于这些文件的确切命名回退顺序的文档,谁能澄清选择扩展名的约定?

Tho*_*key 44

您正在寻找(和评论)的特定代码段位于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. */
Run Code Online (Sandbox Code Playgroud)


mur*_*uru 22

从代码片段的信息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.
Run Code Online (Sandbox Code Playgroud)


rou*_*ble 19

在,眼睛稍微容易一些,正则表达式说:

[._]*.s[a-v][a-z]
[._]*.sw[a-p]
[._]s[a-v][a-z]
[._]sw[a-p]
Run Code Online (Sandbox Code Playgroud)

其来源是 Github 自己的Vim gitignore 文件。

  • 也许更重要的是......你有没有在 git 上推送补丁?:-) (2认同)

chi*_*cks 12

够好了 .gitignore

虽然这里的其他答案在技术上显然更完整,但对于大多数s 来说,这是一个足够好的条目,.gitignore这是我最关心的地方:

# vim swap files
##################
*.sw[a-p]
Run Code Online (Sandbox Code Playgroud)

正如您从其他答案中看到的那样,vim可以创建数百个其他名称,但是在此操作失败之前,您必须堆叠16 个交换文件。通过推广到类似的东西*.s[a-z][a-z]可能看起来更正确,它还将匹配许多有效的扩展名,这.gitignore意味着这些文件不会被git. 在 20 年的使用中vim,我从未设法为同一个文件创建 16 个交换文件,所以我希望您能设法做到这一点,这对您有用。

更严格的版本

正如评论中指出的,Flash 开发人员可能有.swf文件,因此您可能更喜欢

*.sw[g-p]
Run Code Online (Sandbox Code Playgroud)

这仍然会忽略 10 个交换文件,这对大多数人来说已经足够了。唯一可悲的部分是您失去了“交换”助记符。

  • 您可以通过检查前导的 `.` 或 `_` 来避免捕获大多数合法文件,这些文件也被添加。 (4认同)
  • 除非我遗漏了什么,否则只会抓住“swp”,因为下一个是“swo”而不是“swq”。就我个人而言,我使用 "*.sw[ap]" 是因为你给出的原因,也是因为它读作 "swap" :) (3认同)
  • 请记住包含您的 `.swf` 文件。或者将您的 Flash 开发人员升级到 HTML5 :-) (3认同)
  • 我自己发现了 `*.sw[ap]` 助记符。我喜欢它 :) (2认同)

小智 5

这个 .gitignore 替代方案应该让每个人都满意。第二行否定忽略“*.swf”。

*.sw[a-p]
!*.swf
Run Code Online (Sandbox Code Playgroud)