How to debug broken vim completefunc in haml files?
-
18-09-2019 - |
Question
I'm using rails.vim and I love how you can use ctrl-x ctrl-u in insert mode to autocomplete long method names like distance_of_time_in_words
and accepts_nested_attributes_for
. But for some reason it doesn't work in haml files and I can't seem to figure out what's wrong or how to fix it.
:help i_CTRL-X_CTRL-U
says the autocompletion is using completefunc
. The haml file says its completefunc=syntaxcomplete#Complete
(and it's the same in erb and helper files where ctrl-x ctrl-u works fine.) I can't find where the syntaxcomplete#Complete
magic is defined, but presumably it has something to do with the filetype syntax. My .vim/syntax/haml.vim
comes from vim-haml, so I tried removing it but the problem persists.
Commenting out my entire .vimrc
didn't help either. What else can I try?
UPDATE: I searched my vim config files and the only place that looks like it's doing anything with syntaxcomplete#Complete
is in autoload/rails.vim
and looks like this:
function! s:resetomnicomplete()
if exists("+completefunc") && &completefunc == 'syntaxcomplete#Complete'
if exists("g:loaded_syntax_completion")
" Ugly but necessary, until we have our own completion
unlet g:loaded_syntax_completion
silent! delfunction syntaxcomplete#Complete
endif
endif
endfunction
Solution
Functions with # in name are defined in autoload scripts:
A function that can be autoloaded has a name like this:
:call filename#funcname()
When such a function is called, and it is not defined yet, Vim will search the "autoload" directories in 'runtimepath' for a script file called "filename.vim". For example "~/.vim/autoload/filename.vim".
See :help autoload
.
OTHER TIPS
Looks like the file you're looking for is part of vim:
$ find /usr/share/vim/ -iname "syntaxcomplete.vim"
/usr/share/vim/vim72/autoload/syntaxcomplete.vim
There's a vim.org page with the latest version of the script.
If you want to customize the completion, you can just write your own completion function. See :help complete-functions
You can also use Ctrl+n to use vim's simple completion. It completes with text from any of the open files, but can be customized. (See :help 'complete'
)