Youcompleteme: YCM doesn't show suggestions except when using the dot operator.

Created on 9 May 2017  路  4Comments  路  Source: ycm-core/YouCompleteMe

So I got YouCompleteMe working for python autocompletion. Whenever I use a . operator such as:
import sys;
sys.
It shows the correct suggestions. Note that I didn't have to hit CtrlSpace
a

But when I type the word 'import', it doesn't show any suggestion.
b

I have to enter CtrlSpace in order for it to show the correct suggestion.
c

I want it to automatically suggest without me having to press "ctrl-space". Is there a way to fix it?

Btw, here is my output of ':YcmDebugInfo':
d

And the value of my g:ycm_min_num_of_chars_for_completion is 2.

Most helpful comment

You can do that with the g:ycm_semantic_triggers option. For instance, if you want semantic completion to automatically trigger after typing two characters:

let g:ycm_semantic_triggers = {
    \   'python': [ 're!\w{2}' ]
    \ }

or if you just want to automatically complete import statements:

let g:ycm_semantic_triggers = {
    \   'python': [ 're!(import\s+|from\s+(\w+\s+(import\s+(\w+,\s+)*)?)?)' ]
    \ }

All 4 comments

You can do that with the g:ycm_semantic_triggers option. For instance, if you want semantic completion to automatically trigger after typing two characters:

let g:ycm_semantic_triggers = {
    \   'python': [ 're!\w{2}' ]
    \ }

or if you just want to automatically complete import statements:

let g:ycm_semantic_triggers = {
    \   'python': [ 're!(import\s+|from\s+(\w+\s+(import\s+(\w+,\s+)*)?)?)' ]
    \ }

@micbou
Wow! It actually works, thank you. Is it alright if you give me a short explanation of the line
'python': [ 're!\w{2}' ]?
Like what does it mean? Because I want to enable it in javascript as well. Thank you again.

This line adds a list of triggers to the python filetype: re!\w{2} in this case. The re! prefix tells YCM that the rest of the string is a Python regular expression: \w matches any alphanumeric character and {2} repeats the match exactly twice so we are telling YCM to trigger semantic completion for Python when there are exactly two alphanumeric characters.

@micbou Alright thank you!

Was this page helpful?
0 / 5 - 0 ratings