commit 927d4d2a15b8474cd6c605df65ef53873cf73131
parent c50460cf3b02f8e684d038a1ea37e6fdc2d13a09
Author: Christian Clason <c.clason@uni-graz.at>
Date: Sat, 3 Sep 2022 19:27:57 +0200
fix(filetype): run filetype.match on StdinReadPost (#20070)
Problem: filetype detection does not run on piped input
Solution: add `StdinReadPost` to main filetype.lua autocommand
Rationale: legacy filetype detection checked contents by sourcing
`scripts.vim` in separate autocommands, including on `StdinReadPost`.
For Lua filetype detection, this was moved into the main autocommand,
with bundled `scripts.vim` gated behind `g:do_legacy_filetype` (i.e.,
only user `scripts.vim` are sourced for compatibility by default). Adding
`StdinReadPost` to the main autocommand again runs content checks on
piped input without requiring code duplication and low-payoff
refactoring.
Diffstat:
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/runtime/filetype.lua b/runtime/filetype.lua
@@ -6,7 +6,7 @@ vim.g.did_load_filetypes = 1
vim.api.nvim_create_augroup('filetypedetect', { clear = false })
-vim.api.nvim_create_autocmd({ 'BufRead', 'BufNewFile' }, {
+vim.api.nvim_create_autocmd({ 'BufRead', 'BufNewFile', 'StdinReadPost' }, {
group = 'filetypedetect',
callback = function(args)
local ft, on_detect = vim.filetype.match({ filename = args.match, buf = args.buf })