feat(keymaps): configurable map_prefix for the wiki command family (P2)
Mirror vimwiki's g:vimwiki_map_prefix. The whole <Leader>w* family was
hardcoded across the map layer; it is now built from a configurable prefix:
- Neovim: `map_prefix` setup() option (default '<Leader>w'), read by
lua/nuwiki/keymaps.lua (buffer-local) and lua/nuwiki/init.lua (global
entry points).
- Vim: g:nuwiki_map_prefix, applied via :exe in plugin/nuwiki.vim (global)
and ftplugin/vimwiki.vim (buffer-local).
Setting a custom prefix relocates <prefix>{w,t,s,i,n,d,r,c,h,hh,ha} and
<prefix><Leader>{w,y,t,m,i}, leaving nothing under the old <Leader>w*.
Non-prefix maps (<CR>, gl*, headers, …) are untouched.
Tests: new test-keymaps-vim-prefix.vim harness (21 cases, wired into
test-keymaps-vim.sh) + map_prefix.relocates_wiki_family in test-keymaps.lua.
Docs: README, doc/nuwiki.txt, lua config comment, vimwiki-gap.md ticked.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -13,6 +13,11 @@ M.defaults = {
|
||||
syntax = 'vimwiki',
|
||||
log_level = 'warn',
|
||||
|
||||
-- Prefix for the global/buffer wiki command family (`<prefix>w`,
|
||||
-- `<prefix>t`, `<prefix><Leader>w`, …). Mirrors vimwiki's
|
||||
-- `g:vimwiki_map_prefix`. Vim users set `g:nuwiki_map_prefix` instead.
|
||||
map_prefix = '<Leader>w',
|
||||
|
||||
-- Multi-wiki shape. Each entry honours every per-wiki key the
|
||||
-- server understands. Leave nil to fall through to the shorthand
|
||||
-- above.
|
||||
|
||||
+10
-8
@@ -48,15 +48,17 @@ local function _setup_global_mappings()
|
||||
if vim.g.nuwiki_no_default_mappings then return end
|
||||
local kmap = vim.keymap.set
|
||||
local function o(d) return { silent = true, desc = 'nuwiki: ' .. d } end
|
||||
-- Same configurable prefix as the buffer-local maps (vimwiki map_prefix).
|
||||
local p = config.options.map_prefix or '<Leader>w'
|
||||
|
||||
kmap('n', '<Leader>ww', function() _open(_wiki_index_path(0)) end, o('wiki index'))
|
||||
kmap('n', '<Leader>wt', function() _open(_wiki_index_path(0), 'tabedit') end, o('wiki index (tab)'))
|
||||
kmap('n', '<Leader>ws', function() require('nuwiki.commands').wiki_ui_select() end, o('pick wiki'))
|
||||
kmap('n', '<Leader>wi', function() _open(_diary_path(nil)) end, o('diary index'))
|
||||
kmap('n', '<Leader>w<Leader>w', function() _open(_diary_path(0)) end, o('today diary'))
|
||||
kmap('n', '<Leader>w<Leader>y', function() _open(_diary_path(-1)) end, o('yesterday diary'))
|
||||
kmap('n', '<Leader>w<Leader>t', function() _open(_diary_path(1)) end, o('tomorrow diary'))
|
||||
kmap('n', '<Leader>w<Leader>i', function() require('nuwiki.commands').diary_generate_index() end, o('rebuild diary index'))
|
||||
kmap('n', p .. 'w', function() _open(_wiki_index_path(0)) end, o('wiki index'))
|
||||
kmap('n', p .. 't', function() _open(_wiki_index_path(0), 'tabedit') end, o('wiki index (tab)'))
|
||||
kmap('n', p .. 's', function() require('nuwiki.commands').wiki_ui_select() end, o('pick wiki'))
|
||||
kmap('n', p .. 'i', function() _open(_diary_path(nil)) end, o('diary index'))
|
||||
kmap('n', p .. '<Leader>w', function() _open(_diary_path(0)) end, o('today diary'))
|
||||
kmap('n', p .. '<Leader>y', function() _open(_diary_path(-1)) end, o('yesterday diary'))
|
||||
kmap('n', p .. '<Leader>t', function() _open(_diary_path(1)) end, o('tomorrow diary'))
|
||||
kmap('n', p .. '<Leader>i', function() require('nuwiki.commands').diary_generate_index() end, o('rebuild diary index'))
|
||||
end
|
||||
|
||||
-- Global wiki-picker commands so a wiki can be chosen from any buffer before
|
||||
|
||||
+23
-18
@@ -143,17 +143,22 @@ function M.attach(bufnr, mappings)
|
||||
return mappings[group] ~= false
|
||||
end
|
||||
|
||||
-- ===== Wiki prefix (`<Leader>w*`) =====
|
||||
-- Configurable wiki command prefix (vimwiki's `g:vimwiki_map_prefix`).
|
||||
-- Every `<prefix>…` mapping below is built from this so users can relocate
|
||||
-- the whole family by setting `map_prefix` in setup().
|
||||
local p = require('nuwiki.config').options.map_prefix or '<Leader>w'
|
||||
|
||||
-- ===== Wiki prefix (`<prefix>*`, default `<Leader>w*`) =====
|
||||
if on('wiki_prefix') then
|
||||
map('n', '<Leader>ww', function() cmd.wiki_index(0) end, { desc = 'nuwiki: open wiki index' }, bufnr)
|
||||
map('n', '<Leader>wt', function() cmd.wiki_tab_index(0) end, { desc = 'nuwiki: open wiki index (tab)' }, bufnr)
|
||||
map('n', '<Leader>ws', cmd.wiki_ui_select, { desc = 'nuwiki: pick wiki' }, bufnr)
|
||||
map('n', '<Leader>wi', cmd.diary_index, { desc = 'nuwiki: open diary index' }, bufnr)
|
||||
map('n', '<Leader>w<Leader>w', cmd.diary_today, { desc = 'nuwiki: today' }, bufnr)
|
||||
map('n', '<Leader>w<Leader>y', cmd.diary_yesterday, { desc = 'nuwiki: yesterday' }, bufnr)
|
||||
map('n', '<Leader>w<Leader>t', cmd.diary_today_tab, { desc = 'nuwiki: today in a new tab' }, bufnr)
|
||||
map('n', '<Leader>w<Leader>m', cmd.diary_tomorrow, { desc = 'nuwiki: tomorrow (vimwiki <Leader>w<Leader>m)' }, bufnr)
|
||||
map('n', '<Leader>w<Leader>i', cmd.diary_generate_index, { desc = 'nuwiki: rebuild diary index' }, bufnr)
|
||||
map('n', p .. 'w', function() cmd.wiki_index(0) end, { desc = 'nuwiki: open wiki index' }, bufnr)
|
||||
map('n', p .. 't', function() cmd.wiki_tab_index(0) end, { desc = 'nuwiki: open wiki index (tab)' }, bufnr)
|
||||
map('n', p .. 's', cmd.wiki_ui_select, { desc = 'nuwiki: pick wiki' }, bufnr)
|
||||
map('n', p .. 'i', cmd.diary_index, { desc = 'nuwiki: open diary index' }, bufnr)
|
||||
map('n', p .. '<Leader>w', cmd.diary_today, { desc = 'nuwiki: today' }, bufnr)
|
||||
map('n', p .. '<Leader>y', cmd.diary_yesterday, { desc = 'nuwiki: yesterday' }, bufnr)
|
||||
map('n', p .. '<Leader>t', cmd.diary_today_tab, { desc = 'nuwiki: today in a new tab' }, bufnr)
|
||||
map('n', p .. '<Leader>m', cmd.diary_tomorrow, { desc = 'nuwiki: tomorrow (vimwiki <prefix><Leader>m)' }, bufnr)
|
||||
map('n', p .. '<Leader>i', cmd.diary_generate_index, { desc = 'nuwiki: rebuild diary index' }, bufnr)
|
||||
end
|
||||
|
||||
-- ===== Links =====
|
||||
@@ -176,12 +181,12 @@ function M.attach(bufnr, mappings)
|
||||
map('n', '+', cmd.normalize_link, { desc = 'nuwiki: wrap word as wikilink' }, bufnr)
|
||||
map('x', '+', function() cmd.normalize_link(true) end,
|
||||
{ desc = 'nuwiki: wrap selection as wikilink' }, bufnr)
|
||||
map('n', '<Leader>wn', cmd.wiki_goto_page, { desc = 'nuwiki: goto page' }, bufnr)
|
||||
map('n', '<Leader>wd', cmd.delete_file, { desc = 'nuwiki: delete page' }, bufnr)
|
||||
map('n', '<Leader>wr', cmd.rename_file, { desc = 'nuwiki: rename page' }, bufnr)
|
||||
map('n', '<Leader>wc', function() cmd.colorize() end,
|
||||
map('n', p .. 'n', cmd.wiki_goto_page, { desc = 'nuwiki: goto page' }, bufnr)
|
||||
map('n', p .. 'd', cmd.delete_file, { desc = 'nuwiki: delete page' }, bufnr)
|
||||
map('n', p .. 'r', cmd.rename_file, { desc = 'nuwiki: rename page' }, bufnr)
|
||||
map('n', p .. 'c', function() cmd.colorize() end,
|
||||
{ desc = 'nuwiki: wrap word in colour span' }, bufnr)
|
||||
map('x', '<Leader>wc', function() cmd.colorize(nil, true) end,
|
||||
map('x', p .. 'c', function() cmd.colorize(nil, true) end,
|
||||
{ desc = 'nuwiki: wrap selection in colour span' }, bufnr)
|
||||
end
|
||||
|
||||
@@ -301,9 +306,9 @@ function M.attach(bufnr, mappings)
|
||||
|
||||
-- ===== HTML =====
|
||||
if on('html_export') then
|
||||
map('n', '<Leader>wh', cmd.export_current, { desc = 'nuwiki: export to HTML' }, bufnr)
|
||||
map('n', '<Leader>whh', cmd.export_browse, { desc = 'nuwiki: export + browse' }, bufnr)
|
||||
map('n', '<Leader>wha', cmd.export_all, { desc = 'nuwiki: export all' }, bufnr)
|
||||
map('n', p .. 'h', cmd.export_current, { desc = 'nuwiki: export to HTML' }, bufnr)
|
||||
map('n', p .. 'hh', cmd.export_browse, { desc = 'nuwiki: export + browse' }, bufnr)
|
||||
map('n', p .. 'ha', cmd.export_all, { desc = 'nuwiki: export all' }, bufnr)
|
||||
end
|
||||
|
||||
-- ===== Mouse (opt-in via `mappings.mouse = true`) =====
|
||||
|
||||
Reference in New Issue
Block a user