Skip to content

Commit

Permalink
feat(nvim): add filetype plugin
Browse files Browse the repository at this point in the history
Use the plugin to simplify/improve the filetype detection.

See also https://github.com/nathom/filetype.nvim
  • Loading branch information
beiertu-mms committed Jan 30, 2024
1 parent 747e9db commit d5488a3
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 29 deletions.
29 changes: 0 additions & 29 deletions .config/nvim/lua/core/autocmds.lua
Original file line number Diff line number Diff line change
Expand Up @@ -73,32 +73,3 @@ vim.api.nvim_create_autocmd({ 'BufWritePre' }, {
vim.fn.mkdir(vim.fn.fnamemodify(file, ':p:h'), 'p')
end,
})

-- Set terraform-vars filetype to terraform
vim.api.nvim_create_autocmd('BufEnter', {
group = augroup('set_filetype_of_tfvars'),
pattern = '*',
callback = function()
if vim.bo.filetype == 'terraform-vars' then
vim.opt_local.filetype = 'terraform'
end
end,
})

-- Set filetype to helm when the file is in certain paths
vim.api.nvim_create_autocmd({ 'BufNewFile', 'BufRead' }, {
group = augroup('set_filetype_of_helm'),
pattern = { '*/templates/*.yaml', '*/templates/*.tpl', '*.gotmpl', 'helmfile*.yaml' },
callback = function()
vim.opt_local.filetype = 'helm'
end,
})

-- Set filetype to sh for zsh file ending
vim.api.nvim_create_autocmd({ 'BufNewFile', 'BufRead' }, {
group = augroup('set_filetype_of_shell'),
pattern = { '*.zsh' },
callback = function()
vim.opt_local.filetype = 'sh'
end,
})
20 changes: 20 additions & 0 deletions .config/nvim/lua/plugins/filetype.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
return {
-- https://github.com/nathom/filetype.nvim
'nathom/filetype.nvim',
lazy = false,
config = {
overrides = {
extensions = {
gotmpl = 'helm',
tf = 'terraform',
tfvars = 'terraform',
zsh = 'sh',
},
complex = {
['.*/templates/*.yaml'] = 'helm',
['.*/templates/*.tpl'] = 'helm',
['helmfile*.yaml'] = 'helm',
},
},
},
}

0 comments on commit d5488a3

Please sign in to comment.