Skip to content

[Bug Report] ftdetect/*.vim files are sourced twice #706

@laggardkernel

Description

@laggardkernel

Does this bug happen when you install plugin without vim-polyglot?

No

Describe the bug:

From vim --startuptime log, I found my ftdetect/*.vim files are loaded twice. After lots of time digging, I figured out it was related with theses lines in autoload/polyglot/init.vim, first introduces in c45f0b8

" Load user-defined filetype.vim and oter plugins ftdetect first
" This is to use polyglot-defined ftdetect always as fallback to user settings
augroup filetypedetect
  runtime! filetype.vim
  runtime! ftdetect/*.vim
augroup END

To put it in a simple way, runtime! filetype.vim sources share/vim/vim82/filetype.vim, which also run runtime! ftdetect/*.vim

For detailed analysis

Analysis base from verbose log vim -V99debug.log.

Let's begin with how a filetype.vim is loaded. Unlike plugin/ files handled by vim automatically, filetype.vim files are only loaded with executing filetype plugin indent on.

filetype plugin indent on triggers searching for filetype.vim

  • Found this plugin vim-polyglot first, sources vim-ployglot/filetype.vim, which just call polyglot#init#init()

    • Within init.vim
      • Redefine func! polyglot#init#init empty to avoid call loop
      • Calls runtime! filetype.vim
        • Searching for filetype.vim
          • Found vim-ployglot/filetype.vim, skipped
          • Found default share/vim/vim82/filetype.vim
            • Runs runtime! ftdetect/*.vim
              • Search for ftdetect/*.vim and sourcing them (first time loading)
      • Calls runtime! ftdetect/*.vim
        • Search for ftdetect/*.vim and sourcing them (second time loading)
  • It found the default share/vim/vim82/filetype.vim, cause variable did_load_filetypes is set, finish early

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions