yami-beta / asyncomplete-omni.vim

Omni completion source for asyncomplete.vim
MIT License
39 stars 11 forks source link

Is it possible to trigger completion on ( and ,<space> ? #26

Closed statquant closed 3 years ago

statquant commented 3 years ago

Hello, thank you very much for asyncomplete-omni.vim, it works out of the box for vim8 ! I am using "as you type" complete for R in conjunction with Nvim-R. The only feature I am trying to get is for the completion to be triggered after ( and ,<space>

Say I open test.r

If I start to type lib I get image => so that's great

And what I would like it to be able to type plot( and get completion like if I had done plot(<C-X><C-O> image => right now I need to press <C-X><C-O> OR I can define a map like inoremap ( (<C-x><C-o>

Is it doable by way of configuration? Many thanks

PS: I have a small .vimrc (although I think my question might just be plain vim)

"---------------------------------------------------------------
" VIMPLUG
"---------------------------------------------------------------
" Specify a directory for plugins
call plug#begin("/tmp/vim_r_completion/.vim/plugged")
" vim-sensible: https://github.com/tpope/vim-sensible
Plug 'tpope/vim-sensible'
" Nvim-R: https://github.com/jalvesaq/Nvim-R
Plug 'jalvesaq/Nvim-R', {'branch': 'stable', 'for': ['r', 'R', 'rmd', 'Rmd']} 
" https://github.com/yami-beta/asyncomplete-omni.vim
Plug 'prabirshrestha/asyncomplete.vim'
Plug 'yami-beta/asyncomplete-omni.vim'
" Done for all plugins
call plug#end()

call asyncomplete#register_source(asyncomplete#sources#omni#get_source_options({
            \ 'name': 'omni',
            \ 'allowlist': ['*'],
            \ 'blocklist': ['c', 'cpp', 'html'],
            \ 'completor': function('asyncomplete#sources#omni#completor'),
            \ 'config': {
            \   'show_source_kind': 1
            \ }
            \ }))

inoremap <expr> <Tab>   pumvisible() ? "\<C-n>" : "\<Tab>"
inoremap <expr> <S-Tab> pumvisible() ? "\<C-p>" : "\<S-Tab>"
inoremap <expr> <cr>    pumvisible() ? asyncomplete#close_popup() : "\<cr>"

"---------------------------------------------------------------
" NVIMR
"---------------------------------------------------------------
" Press the space bar to send lines (in Normal mode) and selections to R:
vmap <Space> <Plug>RDSendSelection
nmap <Space> <Plug>RDSendLine
yami-beta commented 3 years ago

Thank you report!

How about following config ?

call asyncomplete#register_source(asyncomplete#sources#omni#get_source_options({
            \ 'name': 'omni',
            \ 'allowlist': ['*'],
            \ 'blocklist': ['c', 'cpp', 'html'],
            \ 'completor': function('asyncomplete#sources#omni#completor'),
            \ 'config': {
            \   'show_source_kind': 1
            \ }
            \ 'triggers': { "r": ["("] },
            \ }))

asyncomplete.vim allow to customize completion trigger by triggers option. Default triggers is g:asyncomplete_triggers['*'].

https://github.com/prabirshrestha/asyncomplete.vim/blob/e546095e4ac7a20d06bcf16d207275dd4d6b4115/autoload/asyncomplete.vim#L210-L234

statquant commented 3 years ago

Yes that's perfect thank you very much. g:asyncomplete_triggers is not referenced in the help from what I can see am I looking at the wrong thing ?

I am also trying to disable completion if the line starts by #, it seems that I can achieve this by using g:asyncomplete_preprocessor would that be the advised way ?

yami-beta commented 3 years ago

Maybe, g:asyncomplete_triggers is not documented yet.

I am also trying to disable completion if the line starts by #, it seems that I can achieve this by using g:asyncomplete_preprocessor would that be the advised way ?

Sorry, I'm not familiar with g:asyncomplete_preprocessor.

statquant commented 3 years ago

OK many thanks for your help. Closing if ok with you