Skip to content

Commit

Permalink
feat(autocmds): add auto create dir (#493)
Browse files Browse the repository at this point in the history
* feat(autocmds): add auto create dir

* refactor: auto-create dir

---------

Co-authored-by: Folke Lemaitre <folke.lemaitre@gmail.com>
  • Loading branch information
2giosangmitom and folke committed Mar 31, 2023
1 parent f67f201 commit ed48b85
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions lua/lazyvim/config/autocmds.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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,
})

0 comments on commit ed48b85

Please sign in to comment.