Search code examples
dictionaryvimpopupspell-checking

Dictionary suggestions in autopopup


I use Vim for many years now but I still don't know how to type text with autopopup dictionary suggestions enabled (like in notepad++ or google android keyboard) without pushing any shortcut key.

These are my options in vimrc:

set completeopt=longest,menuone  
set omnifunc=syntaxcomplete#Complete

In short what I want is:
1) Only dictionary suggestion in autopopup while typing.
2) Only buffer words suggestion in supertab (using tab key)
(but..without the buffer names included)

How can I obtain this?


Solution

    1. If you are using Linux you can set the existing english dictionary to /usr/share/dict/american-english or just set your own file:
        :set dictionary+=/usr/share/dict/american-english
    

    and as the shortcut for dictionary completion in insert mode is CTRL-X CTRL-K you need to add these settings:

        :set noshowmode
        :set completeopt+=noinsert
        :autocmd CursorHoldI * call feedkeys("\<c-x>\<c-k>")
        :set updatetime=500
    
    1. You can restrict the Supertab plugin to popup only the buffer words by calling SuperTabSetDefaultCompletionType function (which is actually the default one):
        :call SuperTabSetDefaultCompletionType("<c-x><c-n>")
    

    But you still need to press CTRL-X before TAB.

    1. Disable the NeoComplete plugin
        :NeoCompleteDisable
    

    :help ins-completion
    
    (...)
    
    Completion can be done for:
    
    1. Whole lines                                          i_CTRL-X_CTRL-L
    2. keywords in the current file                         i_CTRL-X_CTRL-N
    3. keywords in 'dictionary'                             i_CTRL-X_CTRL-K
    4. keywords in 'thesaurus', thesaurus-style             i_CTRL-X_CTRL-T
    5. keywords in the current and included files           i_CTRL-X_CTRL-I
    6. tags                                                 i_CTRL-X_CTRL-]
    7. file names                                           i_CTRL-X_CTRL-F
    8. definitions or macros                                i_CTRL-X_CTRL-D
    9. Vim command-line                                     i_CTRL-X_CTRL-V
    10. User defined completion                             i_CTRL-X_CTRL-U
    11. omni completion                                     i_CTRL-X_CTRL-O
    12. Spelling suggestions                                i_CTRL-X_s
    13. keywords in 'complete'                              i_CTRL-N
    

    Edit:

    This is related to comments below this answer: It is a tiny script PopUpDict.vim (it can be improved) that I coded which pop up automatically the matched words in dictionary after typing 3 characters and which give you the ability to pop up the matched buffer keywords after typing ctrl-x tab: (newer version of vim >= 7.4)

    set dictionary+=/usr/share/dict/american-english
    set completeopt+=noinsert
    set cmdheight=2
    call SuperTabSetDefaultCompletionType("<c-x><c-n>")
    NeoCompleteDisable
    
    augroup Main
    autocmd!
    autocmd InsertCharPre * call <SID>PopUpDict()
    augroup END
    
    let s:count=0
    function! s:PopUpDict()
        let AsciiCode=char2nr(v:char)
        if (AsciiCode <=# 122 && AsciiCode >=# 97) || (AsciiCode <=# 90 && AsciiCode >=# 65)  
            let s:count+=1
            if s:count >=# 3
            call feedkeys("\<c-x>\<c-k>")   
            endif
        else
            let s:count=0
        endif
    endfunction
    

    Demo

    enter image description here