My .vimrc
is full of customizations. Like many others, I’ve set options, added plugins, and wrote custom key bindings.
All these personalizations make it hard to debug when something goes wrong.
Everyone has their own VIM. Very few people use VIM out of the box. It’s difficult to troubleshoot problems. Plugins don’t work well together, the wrong options bungle up your configuration, or your operating system is the culprit.
Autocompletion, Language Support, and Styled Components
Lately, I was getting this error:
E117: Unknown function: styledcomplete#CompleteSC
The error pops up when I try to use autocomplete. Vim comes with a completion engine, which you can use with different keyboard shortcuts.
For example, in insert mode, hit CTRL+P
for the previous matching word. Or CTRL+N
for the next matching word.
Here is an overview of the inbuilt options: Let Vim do the typing.
What About Tab Completion?
There are tons of plugins that offer enhanced autocompletion. I use VimCompletesMe.
VimCompletesMe is a lightweight tab-completion package that automatically chooses the right context. It works very well and is fast.
Language Support in Vim
I use different language plugins that enable syntax highlighting, indentation support, and more.
vim-polyglot serves as a “blanket” support plugin. It consolidates different language packs and offers tons of languages. This way, you don’t have to install a language plugin for every language you use.
Styled Components
Syntax highlighting doesn’t work out of the box for Styled Components. But vim-polyglot added this feature in June.
It looks like this plugin is the culprit for my E117
error. Here’s part of the plugin code:
if exists('&ofu')
let b:prevofu=&ofu
 setl omnifunc=styledcomplete#CompleteSC
endif
For now, I’ve just commented out this part of the code, and everything works. I’m not sure why I get this error.
Debugging
What was my process for finding the error?
I first searched the internet with the error message: “E117: Unknown function: styledcomplete#CompleteSC”.
My attempt wasn’t successful.
Then I searched GitHub issues for VimCompletesMe and a general search for Vim and styled-components. Nothing useful.
Then I searched my (Neo)Vim config folder for “styledcomplete#CompletesSC”. You can use ripgrep for that.
ripgrep is a line-oriented search tool that recursively searches your current directory for a regex pattern.
Inside my .config/nvim
folder:
$ rg styledcomplete#CompleteSC
> pack/minpac/start/vim-polyglot/after/ftplugin/javascript.vim
> 87:" setl omnifunc=styledcomplete#CompleteSC
As you can see, it was easy to find (if you know what you’re looking for).
Further Reading
- Let Vim do the typing by George Brocklehurst
- VimCompletesMe
- vim-polyglot
- ripgrep