Skip to content

Commit a8c51a5

Browse files
committed
Do not trigger filetypeindent/filetypeplugin autocmds by default
This is not necessary if `filetype plugin indent on` was not used before `plug#end()`, since then the `FileType` autocmds from there will come after vim-plug's. This will issue a warning, and makes handling of this conditional. This could use `filetype plugin/indent off` to work around this (similar to the `filetype off` being used), but `runtime/indoff.vim` and `runtime/ftplugof.vim` will only empty the augroups, and not remove them. Fixing the user's config is the best solution anyway, so I think a warning is good.
1 parent b4e6465 commit a8c51a5

File tree

1 file changed

+28
-2
lines changed

1 file changed

+28
-2
lines changed

plug.vim

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,8 @@ let s:TYPE = {
109109
\ }
110110
let s:loaded = get(s:, 'loaded', {})
111111
let s:triggers = get(s:, 'triggers', {})
112+
let s:need_filetypeplugin_au = 0
113+
let s:need_filetypeindent_au = 0
112114

113115
function! plug#begin(...)
114116
if a:0 > 0
@@ -209,6 +211,21 @@ function! plug#end()
209211
if exists('g:did_load_filetypes')
210212
filetype off
211213
endif
214+
215+
let warn = []
216+
if exists('g:did_load_ftplugin')
217+
let warn += ['plugin']
218+
let s:need_filetypeindent_au = 1
219+
endif
220+
if exists('g:did_indent_on')
221+
let warn += ['indent']
222+
let s:need_filetypeplugin_au = 1
223+
endif
224+
if !empty(warn)
225+
redraw
226+
call s:warn('echom', printf('[vim-plug] "filetype %s on" should not be used manually with vim-plug, please remove it from your vimrc.', join(warn)))
227+
endif
228+
212229
for name in g:plugs_order
213230
if !has_key(g:plugs, name)
214231
continue
@@ -502,8 +519,17 @@ function! s:lod_ft(pat, names)
502519
let syn = 'syntax/'.a:pat.'.vim'
503520
call s:lod(a:names, ['plugin', 'after/plugin'], syn, 'after/'.syn)
504521
execute 'autocmd! PlugLOD FileType' a:pat
505-
call s:doautocmd('filetypeplugin', 'FileType')
506-
call s:doautocmd('filetypeindent', 'FileType')
522+
523+
" Executing this is only necessary if "filetype plugin indent on" was used
524+
" before plug#end, and can be skipped when Vim has not entered always.
525+
if v:vim_did_enter
526+
if s:need_filetypeplugin_au
527+
call s:doautocmd('filetypeplugin', 'FileType')
528+
endif
529+
if s:need_filetypeindent_au
530+
call s:doautocmd('filetypeindent', 'FileType')
531+
endif
532+
endif
507533
endfunction
508534

509535
function! s:lod_cmd(cmd, bang, l1, l2, args, names)

0 commit comments

Comments
 (0)