天天看點

YCM(YouCompleteMe)不自動提示代碼,逗号提示

現象

我是在ubuntu16.04下安裝的ycm,基本的安裝過程往上很多,這裡就不提了.

目前,主要用ycm來編寫c語言的代碼.ycm隻提示自己輸入的函數,變量,宏等.并不提示系統自帶的庫函數和宏.

但是,當點選點(.)再進行輸入的時候,可以做到提示并補全代碼.是以想應該是沒有配置正确.

解決

google關鍵字ycm+dot得到了網頁

https://github.com/Valloric/YouCompleteMe/issues/2640

這裡的描述類似.答案中有連結到ycm的文檔中.是以在幫助文檔中搜尋triggers關鍵字

得到

The g:ycm_semantic_triggers option

This option controls the character-based triggers for the various semantic completion engines. The option holds a dictionary of key-values, where the keys are Vim’s filetype strings delimited by commas and values are lists of strings, where the strings are the triggers.

Setting key-value pairs on the dictionary adds semantic triggers to the internal default set (listed below). You cannot remove the default triggers, only add new ones.

A “trigger” is a sequence of one or more characters that trigger semantic completion when typed. For instance, C++ (cpp filetype) has . listed as a trigger. So when the user types foo., the semantic engine will trigger and serve foo’s list of member functions and variables. Since C++ also has -> listed as a trigger, the same thing would happen when the user typed foo->.

It’s also possible to use a regular expression as a trigger. You have to prefix your trigger with re! to signify it’s a regex trigger. For instance, re!\w+. would only trigger after the \w+. regex matches.

NOTE: The regex syntax is NOT Vim’s, it’s Python’s.

let g:ycm_semantic_triggers =  {
  \   'c' : ['->', '.'],
  \   'objc' : ['->', '.', 're!\[[_a-zA-Z]+\w*\s', 're!^\s*[^\W\d]\w*\s',
  \             're!\[.*\]\s'],
  \   'ocaml' : ['.', '#'],
  \   'cpp,objcpp' : ['->', '.', '::'],
  \   'perl' : ['->'],
  \   'php' : ['->', '::'],
  \   'cs,java,javascript,typescript,d,python,perl6,scala,vb,elixir,go' : ['.'],
  \   'ruby' : ['.', '::'],
  \   'lua' : ['.', ':'],
  \   'erlang' : [':'],
  \ }
           

大緻意思就是,在ycm_semantic_triggers中定義觸發器的類型.這裡我用的是c語言目前隻有’->’和’.’能用.是以替換c語言那段如下

‘c’ : [ ‘->’ , ‘.’ , ‘re!\w{2}’ ],

其中‘re!\w{2}’ ,re表示regular expression,是該語言的一種正常表達,\w表示任意的字幕,{2}表示當輸入達到兩個字元的時候開始比對符合自動填充的函數,宏等

繼續閱讀