4

I noticed, that in any source code file, regardless of the programming language, I can use the dictionary autocompletion (Ctrl + x Ctrl+k) if the spell option is set, if it's not, then the editor gives an error message, "'dictionary' option is empty".

Is it possible to make the dictionary autocompletion enabled without setting of the spell option?

2 Answers 2

3

I use the following in my vimrc:

inoremap <expr> <c-x><c-k> SpellCheck("\<c-x>\<c-k>")
nnoremap z= :<c-u>call SpellCheck()<cr>z=
function! SpellCheck(...)
  let s:spell_restore = &spell
  set spell
  augroup restore_spell_option
    autocmd!
    autocmd CursorMoved,CompleteDone <buffer> let &spell = s:spell_restore | autocmd! restore_spell_option
  augroup END
  return a:0 ? a:1 : ''
endfunction

The basic idea is to turn on 'spell' for <c-x><c-k> and z= and then restore the previous value of 'spell'. It is a bit clumsy for z= when no spell option is selected, but it works pretty well in practice.

4

The doc :h compl-dictionary says:

CTRL-X CTRL-K        Search the files given with the 'dictionary' option
                     for words that start with the keyword in front of the
                     cursor.
                     [...] By default,
                     the 'dictionary' option is empty.
                     For suggestions where to find a list of words, see the
                     'dictionary' option.

So you simply need to set you 'dictionary' option to get the completion you are looking for

1
  • The docs seem to be a bit incorrect, since CTRL-X CTRL-K works well even if the dictionary option is empty, if the spell option was previously set. I read the entry for the dictionary option and the problem is that I would like not to create a special file. If there was a way to make CTRL-X CTRL-K work without creation of any additional files that would be nice
    – d.k
    Commented Apr 26, 2018 at 16:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.