我是在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}表示当输入达到两个字符的时候开始匹配符合自动填充的函数,宏等