Skip to content

General member auto completion in Python, Java, ...

Enno edited this page Mar 20, 2024 · 4 revisions

The following setup makes <tab>/<plug>(MUcompleteFwd) use omni completion after . preceded by an object outside of comments and strings in python, java, ... Analogously for all other languages that use . to refer to a method or attribute in an object.

let g:mucomplete#can_complete = {
        \ 'python': {'omni': { t -> t =~# '\m[[:keyword:])\]][.]\k*' . '$' && !IsLiteral() }, },
        \ 'java': {'omni': { t -> t =~# '\m[[:keyword:])\]][.]\k*' . '$' && !IsLiteral() }, },
\ }

" similar to definition of b:match_skip in $VIMRUNTIME/ftplugin/vim.vim
let s:literal_zones = '\ccomment\|string'
function! IsLiteral() abort
    let synstack_names = map(synstack(line('.'), max([col('.') - 1, 1])), 'synIDattr(v:val, ''name'')')
    return match(synstack_names, s:literal_zones) >= 0
endfunction
Clone this wiki locally