User statement:

I use Vim to write many technical text documents, including emails.


Is it possible to "store unique words" from past documents in some .vim/file that would be automatically loaded when any future file is opened and the Ctrl+N command is issued? I know others have asked about pointing to a dictionary file in addition to the current file (e.g., https://stackoverflow.com/questions/20887628/vim-auto-complete-both-with-current-file-and-dictionary) but I'd rather the process was dynamic.

Ideal behavior:

I'd like to write one email containing Supercalifragilisticexpialidocious. Then, in some future email, I'd like to start writing Superc and then Ctrl+N would complete the word.

Further thoughts/requests:

  1. I assume there is concern about such a "carryover file" growing excessively large over time. It would be great if it is possible to prevent "words shorter than K characters" from being stored.
  2. I'm also willing/interested in manually editing such a file.
  • 1
    It seems as if you mean by "dynamic" some sort of "vim knows which words I want to add and which I don't" thing. If that's the case, I don't think it's possible. It is, however, possible to add unrecognized-but-correctly-spelled words to a separate dictionary, superuser.com/questions/133208/…
    – MDeBusk
    Jun 29, 2022 at 19:10
  • 1
    Dictionaries are good, as @MDeBusk suggests. But you can also write your own completion (:help compl-function) that might, for example, using readfile()
    – D. Ben Knoble
    Jun 29, 2022 at 19:42

1 Answer 1


As far as I know, the best you can do in this regard is to build a custom dictionary manually and include those new words as part of the matches for Insert mode completion.

In your runtime user directory, create a new directory called spell and in your .vimrc, add the following lines:

set spell
set spellfile=~/.vim/spell/vim-spell-en.utf-8.add
set complete+=kspell

You may want to read :h 'spellfile' and :h spell-load, but basically, vim will store your "custom" words in the path set by spellfile (this file must end in .{encoding}.add). If you only want to use this custom dictionary for a single language, add a prefix for the language as shown above ({language}.{encoding}.add).

After adding your words (with zg), run set spell, type the first letters of your word and press Ctrl+N and you word will be among the suggestions in the pop-up menu.

On your additional requests:

1 - That should be possible by calling a function that

2 - Unfortunately, you cannot manually change this dictionary since this procedure results in a binary file.

  • Regarding point 2 above: (For me) the file ~/.vim/spell/vim-spell-en.utf-8.add is stored in plain text and can be edited.
    – jmlarson
    Jul 1, 2022 at 12:55
  • @jmlarson Yes, but that's not the file vim uses for autocompletion.
    – r_31415
    Jul 1, 2022 at 21:59
  • By the way, I didn't add set spell because I often enable spelling manually, but if you work with text files for which autocomplete is a must-have or spelling is often used, then it is certainly a good idea to enable it by default.
    – r_31415
    Jul 1, 2022 at 22:04

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.