Hello, I am having some issues getting YouCompleteMe to work with CSS. When i create a new .css file, I am not getting any relavant suggestions to automatically pop up. Ctr + Space does show the correct results however.
Is there a way to force YCM to use omnicompletion for .css files?
I am on a Mac using MacVim (ive tried both the downloadable .tgz and installing via Homebrew). I used Vundle to install YCM and have successfully run the ./install.sh with and without clang support. Nothing has made this work.
Here is a copy of my .vimrc: http://pastebin.com/mnD5iqQi
The bottom parts were added as a suggestion from Sixmsj from #vim on freenode. After a number of people tried to help me out they directed me here.
Sorry if I am missing something stupid.
For CSS files, the semantic completion engine that YCM uses is the omnifunc that Vim provides (and that the user can change). Vim comes with an omnifunc for CSS that works well enough. <c-space> works just fine for me in a CSS file.
The only possible problem you could encounter is that YCM currently does not support having a - character in an identifier string, which makes the completion of common CSS property names less than stellar. Issue #86 tracks that problem.
Just for clarification on this point, is there a way to setup YCM so that you don't have to use
@Valloric I think you missed the issue here. It isn't that <c-space> doesn't work, it is that you _have_ to use <c-space> to see the results of the omnicomplete. I'm having a similar issue in a different filetype.
Is there any way to make YouCompleteMe always show the results of the omnicomplete function without forcing you to use <c-space> to see the results?
Is there any way to make YouCompleteMe always show the results of the omnicomplete function without forcing you to use
to see the results?
The omnicomplete engine is a semantic engine in YCM. You get results from the semantic engines when you enter a semantic trigger or manually with <c-space>. YCM has always worked this way.
@Valloric Would it be possible to define a semantic trigger that matches anything at the beginning of a line inside of curly braces? Because that's really what you'd want for CSS. I tried adding to ycm_semantic_triggers but it doesn't seem like that supports multiline matching. Or is there something else I can do to get something similar to a more context aware semantic trigger?
For everyone else on this thread, my workaround at the moment is to add some semantic triggers for CSS:
let g:ycm_semantic_triggers = {
\ 'css': [' ', ': '],
\ }
Those fire after 4 spaces (change it to a tab if you use that for indentation) or after a colon and then space. Ideally this would only fire inside curly braces, but at the moment I don't know it that's possible.
@jpotterm The triggers are line based and not contextual. Anyway if you want to improve your triggers I would suggest some regexp trigger like:
let g:ycm_semantic_triggers = {
\ 'css': [ 're!^\s{4}', 're!:\s+' ],
\ }
So instead of trigger the semantic completion every 4 space it trigger after 4 space on the beginning of a line and the second will trigger even if you type 2 spaces after the :. (Full disclosure: I didn't test it so I could be wrong)
Sorry if this is a stupid question (I don't fully know how vim's completions work) but is there a way to complete attributes and not just values? I am using @vheon's triggers.
@Iambecomeroot Are you using 4 spaces for indentation? You also have to type at least one character to trigger completion.
@micbou 2 spaces. I started typing font and I didn't get any suggestions.
Then you need to change the re!^\s{4} regex to re!^\s{2}:
let g:ycm_semantic_triggers = {
\ 'css': [ 're!^\s{2}', 're!:\s+' ],
\ }
@micbou Thank you! Please pardon my ignorance.
I came up with the following configuration that satisfies me for both CSS and SCSS files:
let g:ycm_semantic_triggers = {
\ 'css': [ 're!^', 're!^\s+', ': ' ],
\ 'scss': [ 're!^', 're!^\s+', ': ' ],
\ }
The 3 triggers means to open the popup window when:
Most helpful comment
@jpotterm The triggers are line based and not contextual. Anyway if you want to improve your triggers I would suggest some regexp trigger like:
So instead of trigger the semantic completion every 4 space it trigger after 4 space on the beginning of a line and the second will trigger even if you type 2 spaces after the
:. (Full disclosure: I didn't test it so I could be wrong)