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.
dictionary file looks like:
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:
" 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)
au CompleteDone * call CompleteSpace()
This could perhaps be optimized a bit, but this seems to be 'good enough' for now ;-)
Unfortunately, this autocmd is not perfect, as documented in the
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 :-)