From 283eec0522fc6af46b89eb6954c96e604c9f761a Mon Sep 17 00:00:00 2001 From: Aaron Dill Date: Thu, 21 Nov 2024 22:30:33 -0600 Subject: [PATCH] feat: read template file if exists --- lua/config/autocmds.lua | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lua/config/autocmds.lua b/lua/config/autocmds.lua index caae4f4..997a59b 100644 --- a/lua/config/autocmds.lua +++ b/lua/config/autocmds.lua @@ -157,3 +157,11 @@ create_autocmd({ "BufEnter", "TermOpen" }, function(e) if vim.bo[e.buf].buftype ~= "terminal" then return end vim.cmd.startinsert() end, { desc = "Enter terminal mode when entering a terminal buffer", group = augroup }) + +create_autocmd("BufNewFile", function(e) + local extension = vim.fn.fnamemodify(e.file, ":e") + if extension == "" then return end + local template = vim.fs.joinpath(vim.fn.stdpath("config"), "templates", "skeleton." .. extension) + if vim.fn.filereadable(template) == 0 then return end -- Return if template does not exist + vim.cmd("silent! 0r " .. vim.fn.fnameescape(template)) +end, { desc = "Template when opening a new file", group = augroup })