diff options
| -rw-r--r-- | README.md | 1 | ||||
| -rw-r--r-- | doc/muwiki.txt | 51 |
2 files changed, 23 insertions, 29 deletions
@@ -49,6 +49,7 @@ Using [lazy.nvim](https://github.com/folke/lazy.nvim): vim.keymap.set('n', '<Tab>', muwiki.next_link, keymap_opts) vim.keymap.set('n', '<S-Tab>', muwiki.prev_link, keymap_opts) vim.keymap.set('v', '<CR>', muwiki.create_link, keymap_opts) + vim.keymap.set('n', '<leader>oo', muwiki.open_link_with, keymap_opts) end, }) end, diff --git a/doc/muwiki.txt b/doc/muwiki.txt index f6fd62a..4576388 100644 --- a/doc/muwiki.txt +++ b/doc/muwiki.txt @@ -111,7 +111,7 @@ Configuration Options:~ Default: false Example:~ - +>lua { url = "https://git.3kgcat.fi/muwiki.nvim/", keys = { @@ -185,7 +185,7 @@ Example:~ }) end, } - +< ============================================================================== 4. COMMANDS AND API *muwiki-commands* @@ -272,36 +272,29 @@ Note: Multi-line selections are not supported. muwiki.nvim provides actions that automatically check if the current buffer is within a configured wiki directory before executing. -Using lazy.nvim:~ -Configure keymaps in the `keys` table: > - { - 'muwiki.nvim', - keys = { - { '<CR>', function() require('muwiki').open_link() end, ft = 'markdown' }, - { '<Tab>', function() require('muwiki').next_link() end, ft = 'markdown' }, - { '<S-Tab>', function() require('muwiki').prev_link() end, ft = 'markdown' }, - { '<CR>', function() require('muwiki').create_link() end, - ft = 'markdown', mode = 'v' }, - { '<leader>oo', function() require('muwiki').open_link_with() end, - ft = 'markdown', desc = 'Open link menu to choose external handler' }, - }, - } - -Manual setup:~ -For other plugin managers, set up your own autocmds: > - vim.api.nvim_create_autocmd('BufEnter', { - pattern = '*.md', - callback = function() - local opts = { buffer = true } - vim.keymap.set('n', '<CR>', require('muwiki').open_link, opts) - vim.keymap.set('n', '<Tab>', require('muwiki').next_link, opts) - vim.keymap.set('n', '<S-Tab>', require('muwiki').prev_link, opts) - vim.keymap.set('v', '<CR>', - require('muwiki').create_link, opts) +Keymap Setup:~ +Configure keymaps using an autocmd to ensure they only apply within wiki +directories: >lua + local muwiki = require('muwiki') + + local group = vim.api.nvim_create_augroup("MuWikiKeymaps", { clear = true }) + + vim.api.nvim_create_autocmd("FileType", { + group = group, + pattern = "markdown", + callback = function(ev) + if not muwiki.wiki_root(ev.buf) then return end + local opts = { buffer = ev.buf, silent = true, nowait = true } + vim.keymap.set('n', '<CR>', muwiki.open_link, opts) + vim.keymap.set('n', '<Tab>', muwiki.next_link, opts) + vim.keymap.set('n', '<S-Tab>', muwiki.prev_link, opts) + vim.keymap.set('v', '<CR>', muwiki.create_link, opts) + vim.keymap.set('n', '<leader>oo', muwiki.open_link_with, opts) end, }) < -Note: Actions check if the buffer is within a configured wiki directory and do nothing if not. +Note: Actions check if the buffer is within a configured wiki directory and +notify the user if not. *muwiki* Actions:~ |
