Vim : 가능한 모든 스왑 파일 확장자는 무엇입니까? 때 현재 파일과 이름은 같지만 .swp확장자가

vim에서 파일을 편집 할 때 현재 파일과 이름은 같지만 .swp확장자가 있는 스왑 파일이 생성됩니다 .

.swp이미 가져온 경우 하나씩 생성합니다 .swo. 이미 찍은 경우 .swa등 을 얻습니다 .

이 파일들에 대한 정확한 네이밍 폴백 순서가 무엇인지에 대한 문서를 찾을 수 없었습니다. 확장자가 선택된 컨벤션으로 누구든지 명확히 할 수 있습니까?



답변

찾고있는 특정 코드 조각은 다음과 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. */


답변

코드 조각의 정보는 빔의 도움으로. 참조 :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.


답변

눈에 약간 더 쉬운 정규 표현식을 사용하십시오.

[._]*.s[a-v][a-z]
[._]*.sw[a-p]
[._]s[a-v][a-z]
[._]sw[a-p]

이에 대한 소스는 Vim 의 Github 자체 gitignore 파일입니다 .


답변

충분하다 .gitignore

여기에있는 다른 답변은 분명히 더 기술적으로 완성되었지만 여기에 내가 가장 자주 관심을 기울인 대부분 의 경우 충분한 항목 .gitignore이 있습니다.

# vim swap files
##################
*.sw[a-p]

다른 답변에서 볼 수 있듯이 vim수백 개의 다른 이름을 만들 수 있지만 실패하기 전에 16 개의 스왑 파일을 쌓아야합니다. *.s[a-z][a-z]보다 정확한 것으로 일반화하면 유효한 확장자많이 일치 .gitignore하므로 파일이 추적되지 않습니다 git. 나는 20 년 동안 동일한 파일에 대해 16 개의 스왑 파일을 만들지 않았 vim으므로 동일한 작업을 수행 할 수 있기를 바랍니다.

더 엄격한 버전

의견에서 지적했듯이 Flash 개발자는 .swf파일을 가지고 있으므로 선호 할 수 있습니다

*.sw[g-p]

대부분의 사람들에게 충분한 스왑 파일 10 개를 여전히 무시합니다. 유일한 슬픈 부분은 “스왑”니모닉을 잃는다는 것입니다.


답변

이 .gitignore 대안은 모든 사람을 만족시켜야합니다. 두 번째 줄은 ‘* .swf’를 무시합니다.

*.sw[a-p]
!*.swf


답변