单词中间的智能单词补全


9

考虑具有以下两行的文件:

someLongFunction
someFunction

当我在第二个单词的中间处于插入模式时

some|Function

我按Ctrl-n,我得到

someLongFunctionFunction

有没有一种配置Vim的方法,以便获得以下“智能”完成信息?

someLongFunction

Answers:


5

以下只是一个快速的模拟答案(即,直到它没有起作用,或者直到它破坏了某些东西为止:)为止),但是它表明“有可能”:

augroup completion
    autocmd!
    autocmd CompleteDone * call PostCompletion()
augroup END

function! PostCompletion()
    if !empty(v:completed_item)
        "check if text after current cursor position is part of the match
        let crt_word = expand('<cWORD>')
        let compl_word = v:completed_item['word']
        let lcw = len(compl_word)
        let leftover = strpart(crt_word, lcw)
        let lfl = len(leftover)
        if lfl > 0
            let endcompl = strpart(compl_word, lcw - lfl)
            if leftover ==# endcompl
                let cpos = getcurpos()
                normal dW
                call setpos('.', cpos)
            endif
        endif
    endif
endfunction

什么上面的代码试图做的是:之后完成,验证是否在光标的WORD比完整单词较长,并且,如果是这样,就进一步检查自己的“剩余”完成的最后部分匹配(在你的榜样, “功能”)。如果是这样,则会删除WORD的其余部分(这假定了有关光标位置的某些内容)。

(我敢肯定,还有更多聪明的方法可以完成所有这些工作,我很想看到它们!)

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.