feat(keymaps): configurable map_prefix for the wiki command family (P2)
CI / cargo fmt --check (push) Failing after 33s
CI / cargo clippy (push) Successful in 31s
CI / cargo test (push) Successful in 41s
CI / editor keymaps (push) Successful in 1m49s

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:
2026-05-31 19:18:06 +00:00
parent 23aec3e6c7
commit feedd30c4d
11 changed files with 234 additions and 55 deletions
+23 -17
View File
@@ -198,17 +198,21 @@ if !has('nvim')
" toggles in lua/nuwiki/keymaps.lua.
if !get(g:, 'nuwiki_no_default_mappings', 0)
" Configurable wiki command prefix (vimwiki's g:vimwiki_map_prefix,
" default <Leader>w). Built with :exe so a custom prefix relocates the
" whole <prefix>* family below.
let s:prefix = get(g:, 'nuwiki_map_prefix', '<Leader>w')
" Wiki prefix
if !get(g:, 'nuwiki_no_wiki_prefix_mappings', 0)
nnoremap <silent><buffer> <Leader>ww :call nuwiki#commands#wiki_index(0)<CR>
nnoremap <silent><buffer> <Leader>wt :call nuwiki#commands#wiki_tab_index(0)<CR>
nnoremap <silent><buffer> <Leader>ws :call nuwiki#commands#wiki_ui_select()<CR>
nnoremap <silent><buffer> <Leader>wi :call nuwiki#commands#diary_index()<CR>
nnoremap <silent><buffer> <Leader>w<Leader>w :call nuwiki#commands#diary_today()<CR>
nnoremap <silent><buffer> <Leader>w<Leader>y :call nuwiki#commands#diary_yesterday()<CR>
nnoremap <silent><buffer> <Leader>w<Leader>t :call nuwiki#commands#diary_today_tab()<CR>
nnoremap <silent><buffer> <Leader>w<Leader>m :call nuwiki#commands#diary_tomorrow()<CR>
nnoremap <silent><buffer> <Leader>w<Leader>i :call nuwiki#commands#diary_generate_index()<CR>
exe 'nnoremap <silent><buffer> ' . s:prefix . 'w :call nuwiki#commands#wiki_index(0)<CR>'
exe 'nnoremap <silent><buffer> ' . s:prefix . 't :call nuwiki#commands#wiki_tab_index(0)<CR>'
exe 'nnoremap <silent><buffer> ' . s:prefix . 's :call nuwiki#commands#wiki_ui_select()<CR>'
exe 'nnoremap <silent><buffer> ' . s:prefix . 'i :call nuwiki#commands#diary_index()<CR>'
exe 'nnoremap <silent><buffer> ' . s:prefix . '<Leader>w :call nuwiki#commands#diary_today()<CR>'
exe 'nnoremap <silent><buffer> ' . s:prefix . '<Leader>y :call nuwiki#commands#diary_yesterday()<CR>'
exe 'nnoremap <silent><buffer> ' . s:prefix . '<Leader>t :call nuwiki#commands#diary_today_tab()<CR>'
exe 'nnoremap <silent><buffer> ' . s:prefix . '<Leader>m :call nuwiki#commands#diary_tomorrow()<CR>'
exe 'nnoremap <silent><buffer> ' . s:prefix . '<Leader>i :call nuwiki#commands#diary_generate_index()<CR>'
endif
" Links
@@ -224,11 +228,11 @@ if !has('nvim')
nnoremap <silent><buffer> <S-Tab> ?\[\[<CR>:nohlsearch<CR>
nnoremap <silent><buffer> + :call nuwiki#commands#normalize_link()<CR>
xnoremap <silent><buffer> + :<C-u>call nuwiki#commands#normalize_link(1)<CR>
nnoremap <silent><buffer> <Leader>wn :call nuwiki#commands#wiki_goto_page('')<CR>
nnoremap <silent><buffer> <Leader>wd :call nuwiki#commands#delete_file()<CR>
nnoremap <silent><buffer> <Leader>wr :call nuwiki#commands#rename_file()<CR>
nnoremap <silent><buffer> <Leader>wc :call nuwiki#commands#colorize('')<CR>
xnoremap <silent><buffer> <Leader>wc :<C-u>call nuwiki#commands#colorize('', 2)<CR>
exe 'nnoremap <silent><buffer> ' . s:prefix . 'n :call nuwiki#commands#wiki_goto_page('''')<CR>'
exe 'nnoremap <silent><buffer> ' . s:prefix . 'd :call nuwiki#commands#delete_file()<CR>'
exe 'nnoremap <silent><buffer> ' . s:prefix . 'r :call nuwiki#commands#rename_file()<CR>'
exe 'nnoremap <silent><buffer> ' . s:prefix . 'c :call nuwiki#commands#colorize('''')<CR>'
exe 'xnoremap <silent><buffer> ' . s:prefix . 'c :<C-u>call nuwiki#commands#colorize('''', 2)<CR>'
endif
" Diary nav
@@ -308,9 +312,9 @@ if !has('nvim')
" HTML export
if !get(g:, 'nuwiki_no_html_export_mappings', 0)
nnoremap <silent><buffer> <Leader>wh :call nuwiki#commands#export_current()<CR>
nnoremap <silent><buffer> <Leader>whh :call nuwiki#commands#export_browse()<CR>
nnoremap <silent><buffer> <Leader>wha :call nuwiki#commands#export_all()<CR>
exe 'nnoremap <silent><buffer> ' . s:prefix . 'h :call nuwiki#commands#export_current()<CR>'
exe 'nnoremap <silent><buffer> ' . s:prefix . 'hh :call nuwiki#commands#export_browse()<CR>'
exe 'nnoremap <silent><buffer> ' . s:prefix . 'ha :call nuwiki#commands#export_all()<CR>'
endif
" Mouse (opt-in via g:nuwiki_mouse_mappings = 1).
@@ -373,6 +377,8 @@ if !has('nvim')
xnoremap <silent><buffer> ic :<C-u>call nuwiki#textobjects#table_column(1)<CR>
onoremap <silent><buffer> ic :<C-u>call nuwiki#textobjects#table_column(1)<CR>
endif
unlet s:prefix
endif
finish