mirror of
https://github.com/LazyVim/LazyVim.git
synced 2026-07-25 14:01:06 +00:00
feat(autocmds): add auto create dir
This commit is contained in:
parent
f67f20184f
commit
cb7a817128
1 changed files with 13 additions and 0 deletions
|
|
@ -67,3 +67,16 @@ 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(ctx)
|
||||
local dir = vim.fn.fnamemodify(ctx.file, ":p:h")
|
||||
local res = vim.fn.isdirectory(dir)
|
||||
|
||||
if res == 0 then
|
||||
vim.fn.mkdir(dir, "p")
|
||||
end
|
||||
end,
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue