From 6c42fb1c098636f6fe7095b418a74e0835b1689d Mon Sep 17 00:00:00 2001 From: Daniel Carrillo Date: Thu, 26 Sep 2024 20:21:33 +0200 Subject: [PATCH] [neovim] Format hcl files on save --- .config/nvim/lua/core/autocommands.lua | 4 ++++ .config/nvim/lua/plugins/lsp/conform.lua | 3 ++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/.config/nvim/lua/core/autocommands.lua b/.config/nvim/lua/core/autocommands.lua index 4059fd2..463f11e 100644 --- a/.config/nvim/lua/core/autocommands.lua +++ b/.config/nvim/lua/core/autocommands.lua @@ -48,6 +48,10 @@ vim.api.nvim_create_autocmd({ "BufNewFile", "BufRead" }, { ]]) end, }) +vim.api.nvim_create_autocmd("FileType", { + pattern = "hcl", + command = "setlocal shiftwidth=2 tabstop=2", +}) -- Disable some plugins on very large files vim.api.nvim_create_autocmd({ "BufEnter" }, { diff --git a/.config/nvim/lua/plugins/lsp/conform.lua b/.config/nvim/lua/plugins/lsp/conform.lua index cd21ab5..fd3ef03 100644 --- a/.config/nvim/lua/plugins/lsp/conform.lua +++ b/.config/nvim/lua/plugins/lsp/conform.lua @@ -8,6 +8,7 @@ require("conform").setup({ python = { "isort", "black" }, typescript = { "prettier" }, yaml = { "prettier" }, + hcl = { "terraform_fmt" }, }, formatters = { { @@ -16,7 +17,7 @@ require("conform").setup({ }, }, format_on_save = function(bufnr) - local filetypes = { "go", "typescript", "lua" } + local filetypes = { "go", "typescript", "lua", "hcl" } if not vim.tbl_contains(filetypes, vim.bo[bufnr].filetype) then return end