feat(autocmds): add auto create dir (#493)

* feat(autocmds): add auto create dir

* refactor: auto-create dir

---------

Co-authored-by: Folke Lemaitre <folke.lemaitre@gmail.com>
This commit is contained in:
Võ Quang Chiến 2023-03-31 14:40:57 +07:00 committed by GitHub
parent f67f20184f
commit ed48b85dbe
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -67,3 +67,12 @@ vim.api.nvim_create_autocmd("FileType", {
vim.opt_local.spell = true
end,
})
-- Auto create dir when saving a file, in case some intermediate directory does not exist
vim.api.nvim_create_autocmd({ "BufWritePre" }, {
group = augroup("auto_create_dir"),
callback = function(event)
local file = vim.loop.fs_realpath(event.match) or event.match
vim.fn.mkdir(vim.fn.fnamemodify(file, ":p:h"), "p")
end,
})