feedd30c4d
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>
68 lines
3.3 KiB
VimL
68 lines
3.3 KiB
VimL
" plugin/nuwiki.vim — universal Vim/Neovim entry point.
|
|
"
|
|
" Neovim 0.11+ users are expected to call `require('nuwiki').setup({})` from
|
|
" their config (lazy.nvim does this automatically through `opts`). On Vim
|
|
" we start the LSP client when a vimwiki buffer is loaded.
|
|
"
|
|
" This file contains wiring only — all logic lives in
|
|
" the Rust language server.
|
|
|
|
if exists('g:loaded_nuwiki')
|
|
finish
|
|
endif
|
|
let g:loaded_nuwiki = 1
|
|
|
|
" Resolve the plugin root NOW, while this script is being sourced and
|
|
" <sfile> is still valid. Commands that need this path must reference
|
|
" s:plugin_root — re-expanding <sfile> inside a command body evaluates
|
|
" at execution time when there is no sourcing context, producing an
|
|
" empty path (hence the E484 "Cannot open ./scripts/…" error).
|
|
let s:plugin_root = fnamemodify(resolve(expand('<sfile>:p')), ':h:h')
|
|
|
|
" :NuwikiInstall — install the nuwiki-ls binary without needing a
|
|
" plugin-manager build hook. Available for both Vim and Neovim.
|
|
if has('nvim')
|
|
command! -nargs=0 NuwikiInstall lua require('nuwiki.install').install()
|
|
else
|
|
command! -nargs=0 NuwikiInstall execute 'source' fnameescape(s:plugin_root . '/scripts/download_bin.vim')
|
|
endif
|
|
|
|
if has('nvim')
|
|
" Neovim path is initialised by `require('nuwiki').setup()`. Nothing else
|
|
" to do at vimscript boot — wait until the user runs setup.
|
|
finish
|
|
endif
|
|
|
|
" Vim path: start the LSP client the first time a vimwiki buffer is opened.
|
|
augroup nuwiki_vim_lsp_start
|
|
autocmd!
|
|
autocmd FileType vimwiki call nuwiki#lsp#start()
|
|
augroup END
|
|
|
|
" Global wiki-picker commands — available from any buffer so a wiki can be
|
|
" chosen before a .wiki file exists. The picker reads its list from config
|
|
" (no LSP); opening the chosen index then auto-starts the server. The
|
|
" buffer-local :VimwikiUISelect in ftplugin/vimwiki.vim shadows these inside
|
|
" wiki buffers but dispatches to the same function.
|
|
command! -nargs=0 VimwikiUISelect call nuwiki#commands#wiki_ui_select()
|
|
command! -nargs=0 NuwikiUISelect call nuwiki#commands#wiki_ui_select()
|
|
|
|
" Global entry-point mappings — work from any buffer, not just .wiki files.
|
|
" 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)
|
|
" 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
|