Currently I'm using pattern
in vim.api.nvim.create_autocmd()
:
vim.api.nvim_create_autocmd({ "BufEnter", "BufFilePost" }, {
pattern = { "*.tf" },
callback = SetTerraformMappings,
group = terraformGrp,
})
But I would prefer to use filetype somehow instead of pattern
. In vimscript I could
autocmd Filetype terraform lua SetTerraformMappings()
Also as a workaround I can just create ~/.config/nvim/after/ftplugin/terraform.vim
with the mappings there:
nnoremap <buffer> <leader>t :Shell terraform plan -out latest.tfplan<cr>
nnoremap <buffer> <leader>r :Shell terraform apply latest.tfplan<cr>
But I wonder, is there an equivalent to autocmd Filetype xxx yyy
in lua nvim_create_autocmd()
?
Note that filetype and pattern are not exactly equivalent because filetypes sometime inspect the contents of the file to do the filetype detection.
vim.cmd('autocmd ...')
.