Skip to content

Commit

Permalink
feat: read template file if exists
Browse files Browse the repository at this point in the history
  • Loading branch information
aarondill committed Nov 22, 2024
1 parent 9537d6a commit 283eec0
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lua/config/autocmds.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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 })

0 comments on commit 283eec0

Please sign in to comment.