[vim/vim] fuzzy and fuzzycollect together (Discussion #15056)

14 views
Skip to first unread message

techntools

unread,
Jun 20, 2024, 3:33:37 AMJun 20
to vim/vim, Subscribed

I am using modified version of https://github.com/maxboisvert/vim-simple-complete

I have set completeopt+=fuzzy to get completions as I type

Using fuzzycollect to get completions with tab

if exists("g:loaded_vim_simple_complete")
  finish
endif

let g:loaded_vim_simple_complete = 1

let g:vsc_completion_command = get(g:, 'vsc_completion_command', "\<C-N>")
let g:vsc_reverse_completion_command = get(g:, 'vsc_reverse_completion_command', "\<C-P>")
let g:vsc_tab_complete = get(g:, 'vsc_tab_complete', 1)
let g:vsc_type_complete = get(g:, 'vsc_type_complete', 1)
let g:vsc_pattern = get(g:, 'vsc_pattern', '\k')

fun! s:CurrentChar()
    return matchstr(getline('.'), '.\%' . col('.') . 'c')
endfun

fun! s:TabCompletePlugin()
    inoremap <expr> <Tab> <SID>TabComplete(0)
    inoremap <expr> <S-Tab> <SID>TabComplete(1)

    fun! s:TabComplete(reverse)
        if s:CurrentChar() =~ g:vsc_pattern || pumvisible()
            call feedkeys("\<cmd>set completeopt+=fuzzycollect\<cr>")
            call feedkeys(a:reverse ? g:vsc_reverse_completion_command : g:vsc_completion_command, 'n')
            call feedkeys("\<cmd>set completeopt-=fuzzycollect\<cr>")
        else
            call feedkeys("\<Tab>", 'n')
        endif

        return ''
    endfun
endfun

fun! s:TypeCompletePlugin()
    augroup TypeCompletePlugin
        autocmd!
        autocmd InsertCharPre * noautocmd call s:TypeComplete()
    augroup END

    fun! s:TypeComplete()
        if !g:vsc_type_complete || pumvisible()
            return
        endif

        if v:char =~# g:vsc_pattern
            call feedkeys(g:vsc_completion_command, 'n')
        endif
    endfun
endfun

if g:vsc_type_complete | call s:TypeCompletePlugin() | endif
if g:vsc_tab_complete  | call s:TabCompletePlugin()  | endif


Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/repo-discussions/15056@github.com>

techntools

unread,
Jul 20, 2024, 1:27:09 PM (2 days ago) Jul 20
to vim/vim, Subscribed

As the fuzzycollect is no more and fuzzy is handling both filtering and collection, I am using fuzzy like this:

if exists("g:loaded_vim_simple_complete")
  finish
endif

let g:loaded_vim_simple_complete = 1

let g:vsc_completion_command = get(g:, 'vsc_completion_command', "\<C-N>")
let g:vsc_reverse_completion_command = get(g:, 'vsc_reverse_completion_command', "\<C-P>")
let g:vsc_tab_complete = get(g:, 'vsc_tab_complete', 1)
let g:vsc_type_complete = get(g:, 'vsc_type_complete', 1)
let g:vsc_pattern = get(g:, 'vsc_pattern', '\k')

fun! s:CurrentChar()
    return matchstr(getline('.'), '.\%' . col('.') . 'c')
endfun

fun! s:TabCompletePlugin()
    inoremap <expr> <Tab> <SID>TabComplete(0)
    inoremap <expr> <S-Tab> <SID>TabComplete(1)

    fun! s:TabComplete(reverse)
        if s:CurrentChar() =~ g:vsc_pattern || pumvisible
()
            
call feedkeys(a:reverse ? g:vsc_reverse_completion_command : g:vsc_completion_command, 'n'
)
        
else
            call feedkeys("\<Tab>", 'n')
        endif

        return ''
    endfun
endfun

fun! s:TypeCompletePlugin()
    augroup TypeCompletePlugin
        autocmd!
        autocmd InsertCharPre * noautocmd call s:TypeComplete()
    augroup END

    fun! s:TypeComplete()
        if !g:vsc_type_complete || pumvisible()
            return
        endif

        if v:char =~# g:vsc_pattern
            call feedkeys("\<cmd>set completeopt-=fuzzy\<cr>")
            call feedkeys(g:vsc_completion_command, 'n')
            call feedkeys("\<cmd>set completeopt+=fuzzy\<cr>")
        
endif
    endfun
endfun

if g:vsc_type_complete | call s:TypeCompletePlugin() | endif
if g:vsc_tab_complete  | call s:TabCompletePlugin()  | endif


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/repo-discussions/15056/comments/10103422@github.com>

Reply all
Reply to author
Forward
0 new messages