diff options
Diffstat (limited to 'README.md')
| -rw-r--r-- | README.md | 28 |
1 files changed, 23 insertions, 5 deletions
@@ -12,7 +12,6 @@ A lightweight wiki plugin for Neovim using standard markdown syntax. - Standard markdown links `[text](url)` - Multiple wiki directories - External link handlers -- Automatic template for new page - Link navigation with custom keymaps See `:help muwiki` for complete documentation and configuration options. @@ -37,14 +36,16 @@ Using [lazy.nvim](https://github.com/folke/lazy.nvim): local muwiki = require('muwiki') muwiki.setup(opts) - local group = vim.api.nvim_create_augroup("MuWikiKeymaps", { clear = true }) + local group = vim.api.nvim_create_augroup("muwiki", { clear = true }) + -- Setup wiki keymaps for markdown files vim.api.nvim_create_autocmd("FileType", { group = group, pattern = "markdown", - callback = function(ev) - if not muwiki.wiki_root(ev.buf) then return end - local keymap_opts = { buffer = ev.buf, silent = true, nowait = true } + callback = function(args) + if not muwiki.wiki_root(args.buf) then return end + + local keymap_opts = { buffer = args.buf, silent = true, nowait = true } vim.keymap.set('n', '<CR>', muwiki.open_link, keymap_opts) vim.keymap.set('n', '<Tab>', muwiki.next_link, keymap_opts) vim.keymap.set('n', '<S-Tab>', muwiki.prev_link, keymap_opts) @@ -52,6 +53,23 @@ Using [lazy.nvim](https://github.com/folke/lazy.nvim): vim.keymap.set('n', '<leader>oo', muwiki.open_link_with, keymap_opts) end, }) + + -- Auto-create parent directories when saving files in wiki + vim.api.nvim_create_autocmd("BufWritePre", { + group = group, + callback = function(args) + local wiki_root = muwiki.wiki_root(args.buf) + if not wiki_root then return end + + local file = args.file + if not vim.startswith(file, wiki_root) then return end + + local dir = vim.fn.fnamemodify(file, ":h") + if vim.fn.isdirectory(dir) == 0 then + vim.fn.mkdir(dir, "p") + end + end, + }) end, } ``` |
