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:
@@ -281,6 +281,7 @@ let g:nuwiki_file_extension = '.wiki'
|
|||||||
let g:nuwiki_log_level = 'warn'
|
let g:nuwiki_log_level = 'warn'
|
||||||
let g:nuwiki_link_severity = 'warn' " 'off'|'hint'|'warn'|'error'
|
let g:nuwiki_link_severity = 'warn' " 'off'|'hint'|'warn'|'error'
|
||||||
let g:nuwiki_no_default_mappings = 0 " set to 1 to skip the keymap layer
|
let g:nuwiki_no_default_mappings = 0 " set to 1 to skip the keymap layer
|
||||||
|
let g:nuwiki_map_prefix = '<Leader>w' " wiki command prefix
|
||||||
let g:nuwiki_no_folding = 0 " set to 1 to skip foldexpr setup
|
let g:nuwiki_no_folding = 0 " set to 1 to skip foldexpr setup
|
||||||
let g:nuwiki_mouse_mappings = 0 " set to 1 to enable mouse maps
|
let g:nuwiki_mouse_mappings = 0 " set to 1 to enable mouse maps
|
||||||
" Drop individual keymap subgroups (mirror the Lua `mappings.<group>` toggles):
|
" Drop individual keymap subgroups (mirror the Lua `mappings.<group>` toggles):
|
||||||
@@ -297,6 +298,7 @@ let g:nuwiki_mouse_mappings = 0 " set to 1 to enable mouse maps
|
|||||||
| `file_extension` | string | `'.wiki'` | any extension, leading `.` |
|
| `file_extension` | string | `'.wiki'` | any extension, leading `.` |
|
||||||
| `syntax` | string | `'vimwiki'` | `'vimwiki'` (`'markdown'` planned) |
|
| `syntax` | string | `'vimwiki'` | `'vimwiki'` (`'markdown'` planned) |
|
||||||
| `log_level` | string | `'warn'` | `'error'` \| `'warn'` \| `'info'` \| `'debug'` |
|
| `log_level` | string | `'warn'` | `'error'` \| `'warn'` \| `'info'` \| `'debug'` |
|
||||||
|
| `map_prefix` | string | `'<Leader>w'` | prefix for the wiki command family (`<prefix>w`, `<prefix>t`, `<prefix><Leader>w`, …); mirrors vimwiki's `g:vimwiki_map_prefix`. Vim users set `g:nuwiki_map_prefix` |
|
||||||
| `folding` | string | `'lsp'` | `'lsp'` \| `'expr'` \| `'off'` |
|
| `folding` | string | `'lsp'` | `'lsp'` \| `'expr'` \| `'off'` |
|
||||||
| `wikis` | list of tables | `nil` | per-wiki tables (see below); wins over the single-wiki shorthand |
|
| `wikis` | list of tables | `nil` | per-wiki tables (see below); wins over the single-wiki shorthand |
|
||||||
| `mappings` | table | all on | keymap subgroups (see below) |
|
| `mappings` | table | all on | keymap subgroups (see below) |
|
||||||
|
|||||||
@@ -0,0 +1,65 @@
|
|||||||
|
" development/tests/test-keymaps-vim-prefix.vim — driven by
|
||||||
|
" development/tests/test-keymaps-vim.sh.
|
||||||
|
"
|
||||||
|
" Custom-prefix regression. The shell driver sets
|
||||||
|
" `g:nuwiki_map_prefix = '<Leader>n'` *before* the ftplugin loads, so this
|
||||||
|
" harness asserts the whole wiki command family relocates under `<Leader>n*`
|
||||||
|
" while nothing remains under the default `<Leader>w*`. Mirrors vimwiki's
|
||||||
|
" `g:vimwiki_map_prefix` and the Lua-side `map_prefix` option.
|
||||||
|
|
||||||
|
let s:results = []
|
||||||
|
let s:pass = 0
|
||||||
|
let s:fail = 0
|
||||||
|
let s:out = $NUWIKI_KEYMAP_RESULTS
|
||||||
|
|
||||||
|
function! s:record(ok, name, detail) abort
|
||||||
|
let l:line = (a:ok ? 'PASS' : 'FAIL') . ' ' . a:name
|
||||||
|
if a:detail !=# ''
|
||||||
|
let l:line .= ' — ' . a:detail
|
||||||
|
endif
|
||||||
|
call add(s:results, l:line)
|
||||||
|
if a:ok
|
||||||
|
let s:pass += 1
|
||||||
|
else
|
||||||
|
let s:fail += 1
|
||||||
|
endif
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! s:has_map(lhs, mode) abort
|
||||||
|
let l:d = maparg(a:lhs, a:mode, 0, 1)
|
||||||
|
return !empty(l:d) && get(l:d, 'buffer', 0)
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
" Every <prefix>* mapping must now live under <Leader>n (prefix = <Leader>n).
|
||||||
|
let s:relocated = [
|
||||||
|
\ ['<Leader>nw', 'n'], ['<Leader>nt', 'n'], ['<Leader>ns', 'n'], ['<Leader>ni', 'n'],
|
||||||
|
\ ['<Leader>n<Leader>w', 'n'], ['<Leader>n<Leader>y', 'n'], ['<Leader>n<Leader>t', 'n'],
|
||||||
|
\ ['<Leader>n<Leader>m', 'n'], ['<Leader>n<Leader>i', 'n'],
|
||||||
|
\ ['<Leader>nn', 'n'], ['<Leader>nd', 'n'], ['<Leader>nr', 'n'], ['<Leader>nc', 'n'],
|
||||||
|
\ ['<Leader>nh', 'n'], ['<Leader>nhh', 'n'], ['<Leader>nha', 'n'],
|
||||||
|
\ ]
|
||||||
|
for s:e in s:relocated
|
||||||
|
let s:ok = s:has_map(s:e[0], s:e[1])
|
||||||
|
call s:record(s:ok ? 1 : 0, 'prefix.relocated.' . s:e[1] . '.' . s:e[0],
|
||||||
|
\ s:ok ? '' : s:e[0] . ' not bound under custom prefix')
|
||||||
|
endfor
|
||||||
|
|
||||||
|
" The default <Leader>w* family must be GONE (relocated, not duplicated).
|
||||||
|
let s:gone = [
|
||||||
|
\ ['<Leader>ww', 'n'], ['<Leader>wr', 'n'], ['<Leader>wh', 'n'],
|
||||||
|
\ ['<Leader>w<Leader>w', 'n'],
|
||||||
|
\ ]
|
||||||
|
for s:e in s:gone
|
||||||
|
let s:ok = !s:has_map(s:e[0], s:e[1])
|
||||||
|
call s:record(s:ok ? 1 : 0, 'prefix.default_gone.' . s:e[1] . '.' . s:e[0],
|
||||||
|
\ s:ok ? '' : s:e[0] . ' still mapped despite custom prefix')
|
||||||
|
endfor
|
||||||
|
|
||||||
|
" Non-prefix maps (links group) are unaffected by the prefix change.
|
||||||
|
let s:cr = s:has_map('<CR>', 'n')
|
||||||
|
call s:record(s:cr ? 1 : 0, 'prefix.cr_unaffected', s:cr ? '' : '<CR> lost')
|
||||||
|
|
||||||
|
call add(s:results, '')
|
||||||
|
call add(s:results, printf('SUMMARY: %d passed, %d failed', s:pass, s:fail))
|
||||||
|
call writefile(s:results, s:out)
|
||||||
|
execute (s:fail == 0 ? 'qall!' : 'cquit!')
|
||||||
@@ -96,7 +96,41 @@ fi
|
|||||||
|
|
||||||
cat "$RESULTS_OPTOUT"
|
cat "$RESULTS_OPTOUT"
|
||||||
|
|
||||||
if grep -qE '^SUMMARY: [0-9]+ passed, 0 failed' "$RESULTS_OPTOUT"; then
|
if ! grep -qE '^SUMMARY: [0-9]+ passed, 0 failed' "$RESULTS_OPTOUT"; then
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# ===== Custom map_prefix run =====
|
||||||
|
# Fresh Vim instance with g:nuwiki_map_prefix set *before* the ftplugin
|
||||||
|
# loads, so we can assert the whole wiki command family relocates under the
|
||||||
|
# custom prefix and nothing remains under the default <Leader>w*.
|
||||||
|
|
||||||
|
VIMRC_PREFIX="$TMP/vimrc-prefix"
|
||||||
|
cat > "$VIMRC_PREFIX" <<EOF
|
||||||
|
set nocompatible
|
||||||
|
let &runtimepath = '$REPO_ROOT' . ',' . &runtimepath
|
||||||
|
let g:nuwiki_map_prefix = '<Leader>n'
|
||||||
|
filetype plugin indent on
|
||||||
|
syntax enable
|
||||||
|
EOF
|
||||||
|
|
||||||
|
RESULTS_PREFIX="$TMP/results-prefix.txt"
|
||||||
|
|
||||||
|
log "running custom-prefix harness…"
|
||||||
|
NUWIKI_KEYMAP_RESULTS="$RESULTS_PREFIX" \
|
||||||
|
timeout 30 vim -e -s -u "$VIMRC_PREFIX" -c "edit $SEED" -c "source $REPO_ROOT/development/tests/test-keymaps-vim-prefix.vim" \
|
||||||
|
</dev/null >"$TMP/vim-prefix.log" 2>&1 || true
|
||||||
|
|
||||||
|
if [[ ! -f "$RESULTS_PREFIX" ]]; then
|
||||||
|
echo 'keymap custom-prefix harness produced no output' >&2
|
||||||
|
echo '--- vim log ---' >&2
|
||||||
|
cat "$TMP/vim-prefix.log" >&2 || true
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
cat "$RESULTS_PREFIX"
|
||||||
|
|
||||||
|
if grep -qE '^SUMMARY: [0-9]+ passed, 0 failed' "$RESULTS_PREFIX"; then
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
exit 1
|
exit 1
|
||||||
|
|||||||
@@ -820,6 +820,36 @@ vim.defer_fn(function()
|
|||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
-- ===== Configurable map_prefix (vimwiki g:vimwiki_map_prefix) =====
|
||||||
|
-- Overriding map_prefix must relocate the whole <prefix>* family. We attach
|
||||||
|
-- to a throwaway scratch buffer with a custom prefix and assert the new
|
||||||
|
-- bindings exist there while the default <Leader>w* ones do not.
|
||||||
|
tobj_case('map_prefix.relocates_wiki_family', function()
|
||||||
|
local config = require('nuwiki.config')
|
||||||
|
local keymaps = require('nuwiki.keymaps')
|
||||||
|
local saved = config.options.map_prefix
|
||||||
|
config.options.map_prefix = '<Leader>n'
|
||||||
|
local buf = vim.api.nvim_create_buf(false, true)
|
||||||
|
vim.api.nvim_set_current_buf(buf)
|
||||||
|
local ok, err = pcall(function()
|
||||||
|
keymaps.attach(buf, { enabled = true, wiki_prefix = true, links = true, html_export = true })
|
||||||
|
local function bmap(lhs)
|
||||||
|
local d = vim.fn.maparg(lhs, 'n', false, true)
|
||||||
|
return not vim.tbl_isempty(d) and d.buffer == 1
|
||||||
|
end
|
||||||
|
for _, lhs in ipairs({
|
||||||
|
'<Leader>nw', '<Leader>nt', '<Leader>n<Leader>w', '<Leader>nr', '<Leader>nh', '<Leader>nha',
|
||||||
|
}) do
|
||||||
|
if not bmap(lhs) then error('relocated map missing: ' .. lhs) end
|
||||||
|
end
|
||||||
|
if bmap('<Leader>ww') then error('<Leader>ww still bound under custom prefix') end
|
||||||
|
end)
|
||||||
|
-- Always restore global state so later cases see the default prefix.
|
||||||
|
config.options.map_prefix = saved
|
||||||
|
vim.api.nvim_buf_delete(buf, { force = true })
|
||||||
|
if not ok then error(err) end
|
||||||
|
end)
|
||||||
|
|
||||||
-- ===== Wiki picker (config-driven, no LSP) =====
|
-- ===== Wiki picker (config-driven, no LSP) =====
|
||||||
-- The picker must build its list from config so it works from any buffer
|
-- The picker must build its list from config so it works from any buffer
|
||||||
-- before the server attaches.
|
-- before the server attaches.
|
||||||
|
|||||||
@@ -134,8 +134,18 @@ fix site.
|
|||||||
`write_page_invokes_custom_wiki2html_converter`,
|
`write_page_invokes_custom_wiki2html_converter`,
|
||||||
`write_rss_uses_base_url_for_public_links` (`html_export.rs`), config
|
`write_rss_uses_base_url_for_public_links` (`html_export.rs`), config
|
||||||
round-trip + defaults (`index_and_config.rs`).
|
round-trip + defaults (`index_and_config.rs`).
|
||||||
- [ ] **`map_prefix`** — `<Leader>w` hardcoded across the map layer.
|
- [x] **`map_prefix`** — `<Leader>w` was hardcoded across the map layer.
|
||||||
_Fix:_ `plugin/nuwiki.vim`, `lua/nuwiki/keymaps.lua`, `ftplugin/vimwiki.vim`.
|
_Fix:_ mirror vimwiki's `g:vimwiki_map_prefix` with a configurable prefix
|
||||||
|
(Neovim `map_prefix` setup option, default `'<Leader>w'`; Vim
|
||||||
|
`g:nuwiki_map_prefix`). The whole wiki command family is now built from the
|
||||||
|
prefix — both entry-point globals (`lua/nuwiki/init.lua`,
|
||||||
|
`plugin/nuwiki.vim`, via `:exe`) and buffer-local maps
|
||||||
|
(`lua/nuwiki/keymaps.lua`, `ftplugin/vimwiki.vim`). 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}` and leaves nothing under the old `<Leader>w*`. Tests: new
|
||||||
|
`test-keymaps-vim-prefix.vim` harness (21 cases, driven by
|
||||||
|
`test-keymaps-vim.sh`) + `map_prefix.relocates_wiki_family`
|
||||||
|
(`test-keymaps.lua`). Docs: README, `doc/nuwiki.txt`, lua config comment.
|
||||||
- [x] **`<M-CR>` badd-link** — was mouse-only (`<MiddleMouse>`) / command-only
|
- [x] **`<M-CR>` badd-link** — was mouse-only (`<MiddleMouse>`) / command-only
|
||||||
(`:VimwikiBaddLink`); upstream binds `<M-CR>` → `VimwikiBaddLink` (confirmed
|
(`:VimwikiBaddLink`); upstream binds `<M-CR>` → `VimwikiBaddLink` (confirmed
|
||||||
against upstream `ftplugin/vimwiki.vim`). _Fix:_ added normal-mode `<M-CR>` →
|
against upstream `ftplugin/vimwiki.vim`). _Fix:_ added normal-mode `<M-CR>` →
|
||||||
|
|||||||
@@ -103,6 +103,7 @@ default): >
|
|||||||
file_extension = '.wiki',
|
file_extension = '.wiki',
|
||||||
syntax = 'vimwiki',
|
syntax = 'vimwiki',
|
||||||
log_level = 'warn',
|
log_level = 'warn',
|
||||||
|
map_prefix = '<Leader>w',
|
||||||
})
|
})
|
||||||
|
|
||||||
<For multiple wikis or per-wiki tuning, use the `wikis` list: >
|
<For multiple wikis or per-wiki tuning, use the `wikis` list: >
|
||||||
@@ -132,6 +133,7 @@ plugin: >
|
|||||||
let g:nuwiki_wiki_root = '~/vimwiki'
|
let g:nuwiki_wiki_root = '~/vimwiki'
|
||||||
let g:nuwiki_file_extension = '.wiki'
|
let g:nuwiki_file_extension = '.wiki'
|
||||||
let g:nuwiki_log_level = 'warn'
|
let g:nuwiki_log_level = 'warn'
|
||||||
|
let g:nuwiki_map_prefix = '<Leader>w'
|
||||||
|
|
||||||
<Top-level options ~
|
<Top-level options ~
|
||||||
|
|
||||||
@@ -152,6 +154,12 @@ plugin: >
|
|||||||
`log_level` warn
|
`log_level` warn
|
||||||
`error` | `warn` | `info` | `debug`. Forwarded to the language server.
|
`error` | `warn` | `info` | `debug`. Forwarded to the language server.
|
||||||
|
|
||||||
|
*nuwiki-config-map-prefix*
|
||||||
|
`map_prefix` '<Leader>w'
|
||||||
|
Prefix for the 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.
|
||||||
|
|
||||||
*nuwiki-config-folding*
|
*nuwiki-config-folding*
|
||||||
`folding` 'lsp'
|
`folding` 'lsp'
|
||||||
`lsp` uses the server's `foldingRange` provider (Neovim 0.11+ wires
|
`lsp` uses the server's `foldingRange` provider (Neovim 0.11+ wires
|
||||||
@@ -253,6 +261,14 @@ Vim-specific globals ~
|
|||||||
`html_export` `<Leader>wh`, `<Leader>whh`, `<Leader>wha`
|
`html_export` `<Leader>wh`, `<Leader>whh`, `<Leader>wha`
|
||||||
`text_objects` `ah`, `ih`, `al`, `il`, `a\`, `i\`, `ac`, `ic`
|
`text_objects` `ah`, `ih`, `al`, `il`, `a\`, `i\`, `ac`, `ic`
|
||||||
|
|
||||||
|
*g:nuwiki_map_prefix*
|
||||||
|
`g:nuwiki_map_prefix` `'<Leader>w'`
|
||||||
|
Prefix for the wiki command family — both the global entry-point maps
|
||||||
|
(`<prefix>w`, `<prefix>t`, `<prefix>s`, `<prefix>i`, `<prefix><Leader>{w,y,
|
||||||
|
t,m,i}`) and the buffer-local ones (`<prefix>{n,d,r,c,h,hh,ha}`). Mirrors
|
||||||
|
vimwiki's `g:vimwiki_map_prefix`. Set it before the plugin loads. Neovim
|
||||||
|
users set the `map_prefix` option in `setup()` instead.
|
||||||
|
|
||||||
*g:nuwiki_no_folding*
|
*g:nuwiki_no_folding*
|
||||||
`g:nuwiki_no_folding` 0
|
`g:nuwiki_no_folding` 0
|
||||||
When 1, the Vim path skips `foldexpr` / `foldmethod` setup.
|
When 1, the Vim path skips `foldexpr` / `foldmethod` setup.
|
||||||
|
|||||||
+23
-17
@@ -198,17 +198,21 @@ if !has('nvim')
|
|||||||
" toggles in lua/nuwiki/keymaps.lua.
|
" toggles in lua/nuwiki/keymaps.lua.
|
||||||
|
|
||||||
if !get(g:, 'nuwiki_no_default_mappings', 0)
|
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
|
" Wiki prefix
|
||||||
if !get(g:, 'nuwiki_no_wiki_prefix_mappings', 0)
|
if !get(g:, 'nuwiki_no_wiki_prefix_mappings', 0)
|
||||||
nnoremap <silent><buffer> <Leader>ww :call nuwiki#commands#wiki_index(0)<CR>
|
exe 'nnoremap <silent><buffer> ' . s:prefix . 'w :call nuwiki#commands#wiki_index(0)<CR>'
|
||||||
nnoremap <silent><buffer> <Leader>wt :call nuwiki#commands#wiki_tab_index(0)<CR>
|
exe 'nnoremap <silent><buffer> ' . s:prefix . 't :call nuwiki#commands#wiki_tab_index(0)<CR>'
|
||||||
nnoremap <silent><buffer> <Leader>ws :call nuwiki#commands#wiki_ui_select()<CR>
|
exe 'nnoremap <silent><buffer> ' . s:prefix . 's :call nuwiki#commands#wiki_ui_select()<CR>'
|
||||||
nnoremap <silent><buffer> <Leader>wi :call nuwiki#commands#diary_index()<CR>
|
exe 'nnoremap <silent><buffer> ' . s:prefix . 'i :call nuwiki#commands#diary_index()<CR>'
|
||||||
nnoremap <silent><buffer> <Leader>w<Leader>w :call nuwiki#commands#diary_today()<CR>
|
exe 'nnoremap <silent><buffer> ' . s:prefix . '<Leader>w :call nuwiki#commands#diary_today()<CR>'
|
||||||
nnoremap <silent><buffer> <Leader>w<Leader>y :call nuwiki#commands#diary_yesterday()<CR>
|
exe 'nnoremap <silent><buffer> ' . s:prefix . '<Leader>y :call nuwiki#commands#diary_yesterday()<CR>'
|
||||||
nnoremap <silent><buffer> <Leader>w<Leader>t :call nuwiki#commands#diary_today_tab()<CR>
|
exe 'nnoremap <silent><buffer> ' . s:prefix . '<Leader>t :call nuwiki#commands#diary_today_tab()<CR>'
|
||||||
nnoremap <silent><buffer> <Leader>w<Leader>m :call nuwiki#commands#diary_tomorrow()<CR>
|
exe 'nnoremap <silent><buffer> ' . s:prefix . '<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 . '<Leader>i :call nuwiki#commands#diary_generate_index()<CR>'
|
||||||
endif
|
endif
|
||||||
|
|
||||||
" Links
|
" Links
|
||||||
@@ -224,11 +228,11 @@ if !has('nvim')
|
|||||||
nnoremap <silent><buffer> <S-Tab> ?\[\[<CR>:nohlsearch<CR>
|
nnoremap <silent><buffer> <S-Tab> ?\[\[<CR>:nohlsearch<CR>
|
||||||
nnoremap <silent><buffer> + :call nuwiki#commands#normalize_link()<CR>
|
nnoremap <silent><buffer> + :call nuwiki#commands#normalize_link()<CR>
|
||||||
xnoremap <silent><buffer> + :<C-u>call nuwiki#commands#normalize_link(1)<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>
|
exe 'nnoremap <silent><buffer> ' . s:prefix . 'n :call nuwiki#commands#wiki_goto_page('''')<CR>'
|
||||||
nnoremap <silent><buffer> <Leader>wd :call nuwiki#commands#delete_file()<CR>
|
exe 'nnoremap <silent><buffer> ' . s:prefix . 'd :call nuwiki#commands#delete_file()<CR>'
|
||||||
nnoremap <silent><buffer> <Leader>wr :call nuwiki#commands#rename_file()<CR>
|
exe 'nnoremap <silent><buffer> ' . s:prefix . 'r :call nuwiki#commands#rename_file()<CR>'
|
||||||
nnoremap <silent><buffer> <Leader>wc :call nuwiki#commands#colorize('')<CR>
|
exe 'nnoremap <silent><buffer> ' . s:prefix . 'c :call nuwiki#commands#colorize('''')<CR>'
|
||||||
xnoremap <silent><buffer> <Leader>wc :<C-u>call nuwiki#commands#colorize('', 2)<CR>
|
exe 'xnoremap <silent><buffer> ' . s:prefix . 'c :<C-u>call nuwiki#commands#colorize('''', 2)<CR>'
|
||||||
endif
|
endif
|
||||||
|
|
||||||
" Diary nav
|
" Diary nav
|
||||||
@@ -308,9 +312,9 @@ if !has('nvim')
|
|||||||
|
|
||||||
" HTML export
|
" HTML export
|
||||||
if !get(g:, 'nuwiki_no_html_export_mappings', 0)
|
if !get(g:, 'nuwiki_no_html_export_mappings', 0)
|
||||||
nnoremap <silent><buffer> <Leader>wh :call nuwiki#commands#export_current()<CR>
|
exe 'nnoremap <silent><buffer> ' . s:prefix . 'h :call nuwiki#commands#export_current()<CR>'
|
||||||
nnoremap <silent><buffer> <Leader>whh :call nuwiki#commands#export_browse()<CR>
|
exe 'nnoremap <silent><buffer> ' . s:prefix . 'hh :call nuwiki#commands#export_browse()<CR>'
|
||||||
nnoremap <silent><buffer> <Leader>wha :call nuwiki#commands#export_all()<CR>
|
exe 'nnoremap <silent><buffer> ' . s:prefix . 'ha :call nuwiki#commands#export_all()<CR>'
|
||||||
endif
|
endif
|
||||||
|
|
||||||
" Mouse (opt-in via g:nuwiki_mouse_mappings = 1).
|
" 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>
|
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>
|
onoremap <silent><buffer> ic :<C-u>call nuwiki#textobjects#table_column(1)<CR>
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
unlet s:prefix
|
||||||
endif
|
endif
|
||||||
|
|
||||||
finish
|
finish
|
||||||
|
|||||||
@@ -13,6 +13,11 @@ M.defaults = {
|
|||||||
syntax = 'vimwiki',
|
syntax = 'vimwiki',
|
||||||
log_level = 'warn',
|
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
|
-- Multi-wiki shape. Each entry honours every per-wiki key the
|
||||||
-- server understands. Leave nil to fall through to the shorthand
|
-- server understands. Leave nil to fall through to the shorthand
|
||||||
-- above.
|
-- above.
|
||||||
|
|||||||
+10
-8
@@ -48,15 +48,17 @@ local function _setup_global_mappings()
|
|||||||
if vim.g.nuwiki_no_default_mappings then return end
|
if vim.g.nuwiki_no_default_mappings then return end
|
||||||
local kmap = vim.keymap.set
|
local kmap = vim.keymap.set
|
||||||
local function o(d) return { silent = true, desc = 'nuwiki: ' .. d } end
|
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', p .. 'w', 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', p .. 't', 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', p .. 's', 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', p .. 'i', 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', p .. '<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', p .. '<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', p .. '<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 .. '<Leader>i', function() require('nuwiki.commands').diary_generate_index() end, o('rebuild diary index'))
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Global wiki-picker commands so a wiki can be chosen from any buffer before
|
-- 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
|
return mappings[group] ~= false
|
||||||
end
|
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
|
if on('wiki_prefix') then
|
||||||
map('n', '<Leader>ww', function() cmd.wiki_index(0) end, { desc = 'nuwiki: open wiki index' }, bufnr)
|
map('n', p .. 'w', 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', p .. 't', 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', p .. 's', cmd.wiki_ui_select, { desc = 'nuwiki: pick wiki' }, bufnr)
|
||||||
map('n', '<Leader>wi', cmd.diary_index, { desc = 'nuwiki: open diary index' }, bufnr)
|
map('n', p .. 'i', cmd.diary_index, { desc = 'nuwiki: open diary index' }, bufnr)
|
||||||
map('n', '<Leader>w<Leader>w', cmd.diary_today, { desc = 'nuwiki: today' }, bufnr)
|
map('n', p .. '<Leader>w', cmd.diary_today, { desc = 'nuwiki: today' }, bufnr)
|
||||||
map('n', '<Leader>w<Leader>y', cmd.diary_yesterday, { desc = 'nuwiki: yesterday' }, bufnr)
|
map('n', p .. '<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', p .. '<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', p .. '<Leader>m', cmd.diary_tomorrow, { desc = 'nuwiki: tomorrow (vimwiki <prefix><Leader>m)' }, bufnr)
|
||||||
map('n', '<Leader>w<Leader>i', cmd.diary_generate_index, { desc = 'nuwiki: rebuild diary index' }, bufnr)
|
map('n', p .. '<Leader>i', cmd.diary_generate_index, { desc = 'nuwiki: rebuild diary index' }, bufnr)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- ===== Links =====
|
-- ===== Links =====
|
||||||
@@ -176,12 +181,12 @@ function M.attach(bufnr, mappings)
|
|||||||
map('n', '+', cmd.normalize_link, { desc = 'nuwiki: wrap word as wikilink' }, bufnr)
|
map('n', '+', cmd.normalize_link, { desc = 'nuwiki: wrap word as wikilink' }, bufnr)
|
||||||
map('x', '+', function() cmd.normalize_link(true) end,
|
map('x', '+', function() cmd.normalize_link(true) end,
|
||||||
{ desc = 'nuwiki: wrap selection as wikilink' }, bufnr)
|
{ desc = 'nuwiki: wrap selection as wikilink' }, bufnr)
|
||||||
map('n', '<Leader>wn', cmd.wiki_goto_page, { desc = 'nuwiki: goto page' }, bufnr)
|
map('n', p .. 'n', cmd.wiki_goto_page, { desc = 'nuwiki: goto page' }, bufnr)
|
||||||
map('n', '<Leader>wd', cmd.delete_file, { desc = 'nuwiki: delete page' }, bufnr)
|
map('n', p .. 'd', cmd.delete_file, { desc = 'nuwiki: delete page' }, bufnr)
|
||||||
map('n', '<Leader>wr', cmd.rename_file, { desc = 'nuwiki: rename page' }, bufnr)
|
map('n', p .. 'r', cmd.rename_file, { desc = 'nuwiki: rename page' }, bufnr)
|
||||||
map('n', '<Leader>wc', function() cmd.colorize() end,
|
map('n', p .. 'c', function() cmd.colorize() end,
|
||||||
{ desc = 'nuwiki: wrap word in colour span' }, bufnr)
|
{ 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)
|
{ desc = 'nuwiki: wrap selection in colour span' }, bufnr)
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -301,9 +306,9 @@ function M.attach(bufnr, mappings)
|
|||||||
|
|
||||||
-- ===== HTML =====
|
-- ===== HTML =====
|
||||||
if on('html_export') then
|
if on('html_export') then
|
||||||
map('n', '<Leader>wh', cmd.export_current, { desc = 'nuwiki: export to HTML' }, bufnr)
|
map('n', p .. 'h', cmd.export_current, { desc = 'nuwiki: export to HTML' }, bufnr)
|
||||||
map('n', '<Leader>whh', cmd.export_browse, { desc = 'nuwiki: export + browse' }, bufnr)
|
map('n', p .. 'hh', cmd.export_browse, { desc = 'nuwiki: export + browse' }, bufnr)
|
||||||
map('n', '<Leader>wha', cmd.export_all, { desc = 'nuwiki: export all' }, bufnr)
|
map('n', p .. 'ha', cmd.export_all, { desc = 'nuwiki: export all' }, bufnr)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- ===== Mouse (opt-in via `mappings.mouse = true`) =====
|
-- ===== Mouse (opt-in via `mappings.mouse = true`) =====
|
||||||
|
|||||||
+13
-9
@@ -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
|
" Files are opened directly from config (no LSP required); the server
|
||||||
" auto-starts via the FileType autocmd once the vimwiki buffer loads.
|
" auto-starts via the FileType autocmd once the vimwiki buffer loads.
|
||||||
if !get(g:, 'nuwiki_no_default_mappings', 0)
|
if !get(g:, 'nuwiki_no_default_mappings', 0)
|
||||||
nnoremap <silent> <Leader>ww :call nuwiki#commands#open_wiki_path(0)<CR>
|
" Prefix mirrors vimwiki's g:vimwiki_map_prefix (default <Leader>w). Built
|
||||||
nnoremap <silent> <Leader>wt :call nuwiki#commands#open_wiki_path(1)<CR>
|
" with :exe so a custom prefix relocates the whole entry-point family.
|
||||||
nnoremap <silent> <Leader>ws :call nuwiki#commands#wiki_ui_select()<CR>
|
let s:prefix = get(g:, 'nuwiki_map_prefix', '<Leader>w')
|
||||||
nnoremap <silent> <Leader>wi :call nuwiki#commands#open_diary_index_path()<CR>
|
exe 'nnoremap <silent> ' . s:prefix . 'w :call nuwiki#commands#open_wiki_path(0)<CR>'
|
||||||
nnoremap <silent> <Leader>w<Leader>w :call nuwiki#commands#open_diary_path(0)<CR>
|
exe 'nnoremap <silent> ' . s:prefix . 't :call nuwiki#commands#open_wiki_path(1)<CR>'
|
||||||
nnoremap <silent> <Leader>w<Leader>y :call nuwiki#commands#open_diary_path(-1)<CR>
|
exe 'nnoremap <silent> ' . s:prefix . 's :call nuwiki#commands#wiki_ui_select()<CR>'
|
||||||
nnoremap <silent> <Leader>w<Leader>t :tabnew<CR>:call nuwiki#commands#open_diary_path(0)<CR>
|
exe 'nnoremap <silent> ' . s:prefix . 'i :call nuwiki#commands#open_diary_index_path()<CR>'
|
||||||
nnoremap <silent> <Leader>w<Leader>m :call nuwiki#commands#open_diary_path(1)<CR>
|
exe 'nnoremap <silent> ' . s:prefix . '<Leader>w :call nuwiki#commands#open_diary_path(0)<CR>'
|
||||||
nnoremap <silent> <Leader>w<Leader>i :call nuwiki#commands#diary_generate_index()<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
|
endif
|
||||||
|
|||||||
Reference in New Issue
Block a user