I looked at the source code last week, and I don't think this is possible. As xaizek pointed out in a comment, this would make completion ambiguous.
However, I've thought of a workaround :-) There's the CompleteDone autocmd, which is run when:
After Insert mode completion is done. Either when something was completed or abandoning completion.
What we can do is write a dictionary not with spaces, but with another character; and use the CompleteDone autocmd to replace this character afterwards.
In my example, I use the underscore (_). I originally tried to use a more "special" character (such as ·), but that doesn't seem to work.
An example dictionary file looks like:
Monty_Python
Monty_Python_Flying_Circus
The_Black_Adder
Captain_Darling
And with this autocmd the underscores get replaced with spaces; it should be fairly obvious how it works, so I'll not explain that any further:
fun! CompleteSpace()
" Save cursor position
let l:save_cursor = getpos(".")
" Get word we just completed ('borrowed' from: http://stackoverflow.com/a/23541748/660921)
let l:word = matchstr(strpart(getline('.'), 0, col('.') - 1), '\k\+$')
" Replace _ with space
let l:new = substitute(l:word, "_", " ", "g")
" Run :s
exe "s/" . l:word . "/" . l:new . "/e"
" Restore cursor
call setpos(".", l:save_cursor)
endfun
if has("patch-7.3-598")
au CompleteDone * call CompleteSpace()
endif
This could perhaps be optimized a bit, but this seems to be 'good enough' for now ;-)
Caveat!
Unfortunately, this autocmd is not perfect, as documented in the todo.txt file:
The CompleteDone autocommand needs some info passed to it:
- The word that was selected (empty if abandoned complete)
- Type of completion: tag, omnifunc, user func.
[..]
Patch to add v:completed_item. (Shougo Matsu, 2013 Nov 29).
The problem is that it might cause side-effects when completing source code as well; for example my_variable_name() gets "fixed" to my variable name. The autocmd below is for all files, you can restrict the autocmd for certain files... There is actually a patch floating around which seems to fix this, but it's not applied yet for whatever reason. Perhaps it's simply forgotten, or maybe it needs some love to fix a minor issue; you could pursue it :-)
Mon..., but think aboutPy...orMonty Py.... How would Vim know how many words go backwards to find the beginning of the pattern to look for? I'm not sure, but this might be the reason why it's done this way. – xaizek Feb 21 '15 at 17:11Monty Python) when you have just typed part of the first (e.g.Mon) there would be no problem. – Gonçalo Ribeiro Feb 21 '15 at 20:28