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
+13 -9
View File
@@ -51,13 +51,17 @@ command! -nargs=0 NuwikiUISelect call nuwiki#commands#wiki_ui_select()
" Files are opened directly from config (no LSP required); the server
" auto-starts via the FileType autocmd once the vimwiki buffer loads.
if !get(g:, 'nuwiki_no_default_mappings', 0)
nnoremap <silent> <Leader>ww :call nuwiki#commands#open_wiki_path(0)<CR>
nnoremap <silent> <Leader>wt :call nuwiki#commands#open_wiki_path(1)<CR>
nnoremap <silent> <Leader>ws :call nuwiki#commands#wiki_ui_select()<CR>
nnoremap <silent> <Leader>wi :call nuwiki#commands#open_diary_index_path()<CR>
nnoremap <silent> <Leader>w<Leader>w :call nuwiki#commands#open_diary_path(0)<CR>
nnoremap <silent> <Leader>w<Leader>y :call nuwiki#commands#open_diary_path(-1)<CR>
nnoremap <silent> <Leader>w<Leader>t :tabnew<CR>:call nuwiki#commands#open_diary_path(0)<CR>
nnoremap <silent> <Leader>w<Leader>m :call nuwiki#commands#open_diary_path(1)<CR>
nnoremap <silent> <Leader>w<Leader>i :call nuwiki#commands#diary_generate_index()<CR>
" Prefix mirrors vimwiki's g:vimwiki_map_prefix (default <Leader>w). Built
" with :exe so a custom prefix relocates the whole entry-point family.
let s:prefix = get(g:, 'nuwiki_map_prefix', '<Leader>w')
exe 'nnoremap <silent> ' . s:prefix . 'w :call nuwiki#commands#open_wiki_path(0)<CR>'
exe 'nnoremap <silent> ' . s:prefix . 't :call nuwiki#commands#open_wiki_path(1)<CR>'
exe 'nnoremap <silent> ' . s:prefix . 's :call nuwiki#commands#wiki_ui_select()<CR>'
exe 'nnoremap <silent> ' . s:prefix . 'i :call nuwiki#commands#open_diary_index_path()<CR>'
exe 'nnoremap <silent> ' . s:prefix . '<Leader>w :call nuwiki#commands#open_diary_path(0)<CR>'
exe 'nnoremap <silent> ' . s:prefix . '<Leader>y :call nuwiki#commands#open_diary_path(-1)<CR>'
exe 'nnoremap <silent> ' . s:prefix . '<Leader>t :tabnew<CR>:call nuwiki#commands#open_diary_path(0)<CR>'
exe 'nnoremap <silent> ' . s:prefix . '<Leader>m :call nuwiki#commands#open_diary_path(1)<CR>'
exe 'nnoremap <silent> ' . s:prefix . '<Leader>i :call nuwiki#commands#diary_generate_index()<CR>'
unlet s:prefix
endif