1

Let's assume you have the following completefunc defintion:

vim9script

const py_keywords = [
    { 'word': 'pandas.api.extensions.ExtensionArray.argsort'},
    { 'word': 'pandas.api.extensions.ExtensionArray.astype'}
    ]

def PyComplete(findstart: number, base: string): any
    if findstart
        # locate the start of the word
        var line = getline('.')
        var start = col('.') - 1
        while start > 0 && line[start - 1] =~ '[0-9A-Za-z_.]'
            start -= 1
        endwhile
        return start
    else
        var pattern = '.*' .. base .. '.*'
        var matches = copy(py_keywords)->filter((i, x) => x.word =~ pattern)
        for m in matches
            complete_add(m)
        endfor
        return []
    endif
enddef

set completefunc=PyComplete

Notice that instead of the commonly used '^' .. base pattern matching, this is filtering based on substrings '.*' .. base .. '.*'. The previous function works well when you start from very beginning of the matches (in this example, with the letter p) and keep typing in order to reduce the number of suggestions. However, the menu immediately closes when you start from any other substring (e.g. arg). This behavior can be seen in the following screencast:

enter image description here

Is there some way to prevent this behavior?

2
  • I can't really find a good way to do this; the completion is "prefix based". Hooking in to CompleteDonePre or TextChangedP to show the menu again when desired is probably the best bet, but I can't really get that to work right now either. Sep 23 at 11:49
  • Exactly. I also had the impression that completion is prefix based regardless of the pattern match used in either iteration. If there is not a simple way to do this, maybe this could be a good feature request.
    – r_31415
    Sep 23 at 16:06

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.