lervag / wiki.vim

A wiki plugin for Vim
MIT License
643 stars 69 forks source link

ncm2+wiki vim autocomplete doesn't seem to work #226

Closed flancian closed 1 year ago

flancian commented 2 years ago

Description

I've followed the docs (I think :)), installing ncm2 and then adding the relevant my_cm_setup block in .vimrc (which I see was sourced from https://github.com/lervag/wiki.vim/issues/163).

For some reason, though, writing [[ fails to trigger wiki vim autocompletion; instead, when I keep writing, "regular" (file based) ncm2 autocompletion seems to kick in.

That is, this is what I get when writing [[:

image

And this is what I get when writing [[test:

image

(which is the same I get if I just type test anywhere):

image

Minimal working example

Relevant .vimrc:

Plugin 'gabrielelana/vim-markdown'
Plugin 'ncm2/ncm2'
Plugin 'roxma/nvim-yarp'
" NOTE: you need to install completion sources to get completions. Check
" our wiki page for a list of sources: https://github.com/ncm2/ncm2/wiki
Plugin 'ncm2/ncm2-bufword'
Plugin 'ncm2/ncm2-path'
" I prefer [[wiki vim]]
" Plugin 'vimwiki/vimwiki'
Plugin 'lervag/wiki.vim'
let g:wiki_root = '~/garden'
let g:wiki_filetypes = ['md']
let g:wiki_link_extension = '.md'
let g:wiki_write_on_nav = 1
let g:wiki_resolver = 'WikiResolver'

" commandt / ctrlp.
let mapleader=","
call vundle#end()            " required
filetype plugin indent on    " requirePlugin 'mxw/vim-jsx'

" https://github.com/lervag/wiki.vim/issues/225
" this lets following links from journal/ work as I want (resolving to notes
" in the repo root.)
function! WikiResolver(fname, origin) abort
  if empty(a:fname) | return a:origin | endif

  let l:name = fnamemodify(a:fname, ':t:r')
  let l:ext = fnamemodify(a:fname, ':e')
  let l:path = l:name =~# '^\d\{4}-\d\{2}-\d\{2}'
        \ ? wiki#get_root() . '/journal/'. l:name
        \ : wiki#get_root() . '/'. l:name

  return l:path . '.md'
endfunction

" enable ncm2 for all buffers
autocmd BufEnter * call ncm2#enable_for_buffer()

" IMPORTANT: :help Ncm2PopupOpen for more information
"set completeopt=noinsert,menuone,noselect
"
au User Ncm2PopupOpen set completeopt=noinsert,menuone,noselect
au User Ncm2PopupClose set completeopt=menuone

augroup my_cm_setup
autocmd!
autocmd BufEnter * call ncm2#enable_for_buffer()
autocmd User WikiBufferInitialized call ncm2#register_source({
        \ 'name': 'wiki',
        \ 'priority': 9,
        \ 'scope': ['wiki'],
        \ 'word_pattern': '\w+',
        \ 'complete_pattern': '\[\[',
        \ 'on_complete': ['ncm2#on_complete#delay', 200,
        \                 'ncm2#on_complete#omni',
        \                 'wiki#complete#omnicomplete'],
        \})
augroup END

Thank you for your attention!

lervag commented 2 years ago

I've followed the docs (I think :)), installing ncm2 and then adding the relevant my_cm_setup block in .vimrc (which I see was sourced from #163).

For some reason, though, writing [[ fails to trigger wiki vim autocompletion; instead, when I keep writing, "regular" (file based) ncm2 autocompletion seems to kick in.

Strange. I don't use ncm2 myself, and so I don't know that much about it. Can you first confirm that doing [[<c-x><c-o> works as expected - without ncm2? I.e., that the regular omnicompletion works.