aboutsummaryrefslogtreecommitdiff
path: root/README.md
blob: c43671acf3d77040c65bd1611b38651ded8d38ff (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
# muwiki.nvim

A lightweight wiki plugin for Neovim using standard markdown syntax.

## Requirements

- Neovim v0.10+
- Treesitter markdown parsers (`:TSInstall markdown markdown_inline`)

## Features

- Standard markdown links `[text](url)`
- Multiple wiki directories
- External link handlers
- Link navigation with custom keymaps

See `:help muwiki` for complete documentation and configuration options.

## Installation

Using [lazy.nvim](https://github.com/folke/lazy.nvim):

```lua
{
  url = "https://git.3kgcat.fi/muwiki.nvim",
  keys = {
    { "<leader>ww", function() require("muwiki").open_index("default") end, desc = "Open wiki index" },
  },
  opts = {
    -- Wiki directories (REQUIRED - configure at least one)
    dirs = {{ name = 'default', path = '~/wiki' }},
  },

  -- autogroup only loads keymaps in wiki files
  config = function(_, opts)
    local muwiki = require('muwiki')
    muwiki.setup(opts)

    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(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)
        vim.keymap.set('v', '<CR>', muwiki.create_link, keymap_opts)
        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,
}
```

**Available actions:**

- `open_link()` - Open link under cursor
- `next_link()` - Jump to next markdown link
- `prev_link()` - Jump to previous markdown link
- `create_link()` - Create link from visual selection
- `open_link_with()` - Open link with custom external handler

See `:help muwiki-commands` for complete API documentation.

## Link Format

```text
[Wiki page](page.md)
[Website](https://example.com)
[Relative path](file://../document.pdf)
[Absolute path](file:///tmp/image.png)
```

## External Handlers

Define custom handlers for opening external URLs and files:

```lua
external_handlers = {
  -- Open HTTP/HTTPS URLs in Firefox
  {
    name = 'Firefox',
    cmd = 'firefox',
    pattern = '^https?://',
  },
  -- Open videos with mpv (local files and YouTube)
  {
    name = 'mpv',
    cmd = 'mpv',
    pattern = {
      '%.mp4$',
      '%.mkv$',
      '%.avi$',
      '%.webm$',
      'youtube%.com',
      'youtu%.be',
    },
  },
  -- Open images with swayimg
  {
    name = 'swayimg',
    cmd = 'swayimg',
    pattern = {
      '%.png$',
      '%.jpe?g$',
      '%.gif$',
      '%.webp$',
      '%.bmp$',
    },
  },
  -- Copy URL to clipboard using wl-copy
  {
    name = 'Copy URL',
    cmd = function(url)
      vim.system({ 'wl-copy', url }, { detach = true })
      vim.notify('URL copied to clipboard', vim.log.levels.INFO)
    end,
    pattern = '.*',
  },
  -- Fallback for any URL (Linux)
  {
    name = 'xdg-open',
    cmd = 'xdg-open',
    pattern = '.*',
  },
}
```

**Handler properties:**

- `name` - Display name in the handler menu
- `cmd` - Command string or Lua function
- `pattern` - Lua pattern(s) to match URLs (string or table of strings; optional, matches all if omitted)

**Note:** Files with extensions in `text_extensions` will always open in Neovim, bypassing external handlers.

## Recommended Plugins

These plugins work well with muwiki.nvim:

- [render-markdown.nvim](https://github.com/MeanderingProgrammer/render-markdown.nvim) - Improve markdown rendering in Neovim
- [outline.nvim](https://github.com/hedyhli/outline.nvim) - Navigate document structure with symbols outline

See `:help muwiki` for full documentation.