fix(mappings): add global entry-point keymaps and correct <Leader>ww/<Leader>wt targets
Two bugs prevented keymaps from working after a Dein install: 1. <Leader>ww and <Leader>wt both called diary_today() instead of wiki_index() / wiki_tab_index(). Fixed in keymaps.lua (Neovim) and ftplugin/vimwiki.vim (Vim). 2. All keymaps were buffer-local (<buffer> / buffer=bufnr), so they only activated inside an already-open .wiki file. Users had no way to reach the wiki from any other buffer, making the plugin appear broken on a fresh Vim start. Fix: register the eight <Leader>w* entry-point mappings globally — in setup() for Neovim (lua/nuwiki/init.lua) and in plugin/nuwiki.vim for plain Vim. To avoid a chicken-and-egg LSP dependency, the global mappings open files directly from config (wiki_root, diary_rel_path, file_extension); the LSP auto-starts via the FileType autocmd once the vimwiki buffer loads. Three new autoload helpers (open_wiki_path, open_diary_path, open_diary_index_path) provide the LSP-free path for the Vim side. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -342,6 +342,36 @@ function! nuwiki#commands#diary_generate_index() abort
|
||||
call s:exec('nuwiki.diary.generateIndex', [{ 'uri': s:buf_uri() }])
|
||||
endfunction
|
||||
|
||||
" ===== Global entry-point helpers (no LSP required) =====
|
||||
"
|
||||
" These are used by the global mappings in plugin/nuwiki.vim so users can
|
||||
" open their wiki from any buffer. Files are opened directly from config;
|
||||
" the LSP auto-starts via the FileType autocmd once the buffer loads.
|
||||
|
||||
function! nuwiki#commands#open_wiki_path(tab) abort
|
||||
let l:root = expand(get(g:, 'nuwiki_wiki_root', '~/vimwiki'))
|
||||
let l:ext = get(g:, 'nuwiki_file_extension', '.wiki')
|
||||
if l:ext[0] !=# '.' | let l:ext = '.' . l:ext | endif
|
||||
execute (a:tab ? 'tabedit' : 'edit') . ' ' . fnameescape(l:root . '/index' . l:ext)
|
||||
endfunction
|
||||
|
||||
function! nuwiki#commands#open_diary_path(day_offset) abort
|
||||
let l:root = expand(get(g:, 'nuwiki_wiki_root', '~/vimwiki'))
|
||||
let l:ext = get(g:, 'nuwiki_file_extension', '.wiki')
|
||||
if l:ext[0] !=# '.' | let l:ext = '.' . l:ext | endif
|
||||
let l:diary = get(g:, 'nuwiki_diary_rel_path', 'diary')
|
||||
let l:date = strftime('%Y-%m-%d', localtime() + a:day_offset * 86400)
|
||||
execute 'edit ' . fnameescape(l:root . '/' . l:diary . '/' . l:date . l:ext)
|
||||
endfunction
|
||||
|
||||
function! nuwiki#commands#open_diary_index_path() abort
|
||||
let l:root = expand(get(g:, 'nuwiki_wiki_root', '~/vimwiki'))
|
||||
let l:ext = get(g:, 'nuwiki_file_extension', '.wiki')
|
||||
if l:ext[0] !=# '.' | let l:ext = '.' . l:ext | endif
|
||||
let l:diary = get(g:, 'nuwiki_diary_rel_path', 'diary')
|
||||
execute 'edit ' . fnameescape(l:root . '/' . l:diary . '/diary' . l:ext)
|
||||
endfunction
|
||||
|
||||
" ===== List + heading editing =====
|
||||
|
||||
function! s:exec_pos(cmd) abort
|
||||
|
||||
Reference in New Issue
Block a user