feat(nvim): add autocmd to create a new dir when saving a file inside (removed mkdir.nvim extra)

This commit is contained in:
sankalp committed 2024-02-10 14:42:51 +05:45
1 parent bff8305e3f
commit ff77cde1c7
7 files changed
+103 -54

No files matched your search

+12
View File
@@ -128,3 +128,15 @@ au({ "BufLeave", "FocusLost", "InsertEnter", "CmdlineEnter", "WinLeave" }, {
end
end,
})
-- Create a dir when saving a file if it doesnt exist
au("BufWritePre", {
group = ag("auto_create_dir", { clear = true }),
callback = function(args)
if args.match:match("^%w%w+://") then
return
end
local file = vim.loop.fs_realpath(args.match) or args.match
vim.fn.mkdir(vim.fn.fnamemodify(file, ":p:h"), "p")
end,
})