Files
dotfiles/vim/.vim/lua/config/tmpl.lua
Christian Nieves 38f84a6dd9 fix autoformat
2024-12-12 17:16:42 +00:00

30 lines
894 B
Lua

vim.api.nvim_create_autocmd({ 'BufRead', 'BufNewFile' }, {
group = vim.api.nvim_create_augroup('gotmpl_highlight', { clear = true }),
pattern = '*.tmpl',
callback = function()
local filename = vim.fn.expand('%:t')
local ext = filename:match('.*%.(.-)%.tmpl$')
-- Add more extension to syntax mappings here if you need to.
local ext_filetypes = {
go = 'go',
html = 'html',
md = 'markdown',
yaml = 'yaml',
yml = 'yaml',
}
if ext and ext_filetypes[ext] then
-- Set the primary filetype
vim.bo.filetype = ext_filetypes[ext]
-- Define embedded Go template syntax
vim.cmd([[
syntax include @gotmpl syntax/gotmpl.vim
syntax region gotmpl start="{{" end="}}" contains=@gotmpl containedin=ALL
syntax region gotmpl start="{%" end="%}" contains=@gotmpl containedin=ALL
]])
end
end,
})