C语言 Eclipse 中的 C 代码自动完成

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2507981/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 04:55:57  来源:igfitidea点击:

C code autocomplete in Eclipse

ceclipseautocomplete

提问by Ittai

I'm a Java developer and I've downloaded the Eclipse for C (course purposes) and to my amazement the control+space shortcut (for autocomplete) did not work. I've created a new project and a new class using the wizzards and started to type "print" and then tried to find an autocomplete feature. After a bit of googling I arrived at C/C++->Editor->Content Assist->Advancedand there I verified that Help proposals,Parsing-based proposalsand Template proposalsoptions were checked. I then went over to the Keyspreferences page using the link at that page and entered a binding for all relevant content assist from before C\C++ Content Assist (type...)and chose in the Whenbox the C\C++ Editoroption. But alas no autocompletion was offered. Can someone please point me to the right direction?

我是一名 Java 开发人员,我已经为 C(课程目的)下载了 Eclipse,令我惊讶的是 control+space 快捷方式(用于自动完成)不起作用。我使用向导创建了一个新项目和一个新类,并开始键入“打印”,然后尝试查找自动完成功能。经过一番谷歌搜索后,我到达了C/C++-> Editor-> Content Assist->Advanced并在那里验证了Help proposalsParsing-based proposalsTemplate proposals检查了选项。然后,我Keys使用该页面上的链接转到首选项页面,并为之前的所有相关内容辅助输入绑定,然后C\C++ Content Assist (type...)When框中选择该C\C++ Editor选项。但可惜没有提供自动完成功能。有人可以指出我正确的方向吗?

UPDATE:I'm accepting the answer not because I'm sure it's right but because I've realised I've made some mistakes with the configuration of the eclipse and have seen that with another installation/configuration (i.e. a friend of mines) eclipse does auto complete, even if it still lack many of the java version features.

更新:我接受答案不是因为我确定它是正确的,而是因为我意识到我在 eclipse 的配置上犯了一些错误,并且在另一个安装/配置中看到了这一点(即我的朋友) eclipse 会自动完成,即使它仍然缺乏许多 java 版本的功能。

采纳答案by Yousf

Although the eclipse doesn't provide perfect auto-complete, but it works.. This sometimes happens when you have the indexer turned off.

尽管 Eclipse 没有提供完美的自动完成功能,但它确实有效。当您关闭索引器时,有时会发生这种情况。

Try to enable the indexer and rebuild the index.

尝试启用索引器并重建索引。

See this question in CDT FAQ. It contains info about how to find indexer error which might prevent auto-complete.

请参阅CDT 常见问题解答中的此问题。它包含有关如何查找可能会阻止自动完成的索引器错误的信息。

回答by Sunil

Use the Advanced panel in the Preferences window to configure the behavior of the Content Assist (Ctrl+Space) command.
Go to Preferences->C/C++->Editor->Content Assist->Advanced.
Check the parsing-based-Proposalsin Default Proposal kinds.

使用“首选项”窗口中的“高级”面板配置内容辅助 (Ctrl+Space) 命令的行为。
转到Preferences->C/C++->Editor->Content Assist->Advanced
检查默认提案种类中的基于解析的提案。

回答by caf

I'm no Eclipse expert (and I don't even play one on TV), but it might be that it only autocompletes function names that are declared in the current scope - have you added #include <stdio.h>to the top of your source file to get the declarations for the standard I/O functions?

我不是 Eclipse 专家(我什至不在电视上玩),但它可能只自动完成在当前范围内声明的函数名称 - 您是否已将其添加#include <stdio.h>到源文件的顶部以获取标准 I/O 函数的声明?

回答by Ittai


You should verify that you have the gcc home (i.e. C:\MinGW-4.4.1\bin) defined in the path environment variable (if you're using windows and if not then it's equivelant). Also verify that the file has a .c suffix and that the indexer is on as yousf said. I think, not sure, that you need to then run eclipse with the -clean flag and the autocomplete will work.


您应该验证路径环境变量中是否定义了 gcc home(即 C:\MinGW-4.4.1\bin)(如果您使用的是 windows,如果不是,则它是等效的)。还要验证文件是否具有 .c 后缀,并且索引器是否如 yousf 所说的那样打开。我认为,不确定,然后您需要使用 -clean 标志运行 eclipse 并且自动完成功能将起作用。

Ittai

伊泰

回答by Tom Sengelaub

i answered it here: Eclipse: How to add include path to be used by autocompletion

我在这里回答: Eclipse: How to add include path to be used by autocompletion

You have to explicitly tell it where to find the header:

? Right click on your project
? go to 'C/C++ Include Paths and Symbols'
? select 'Add External Include Path...'
? browse to the location of your header files
? refresh

您必须明确告诉它在哪里可以找到标题:

? 右键单击您的项目
?转到“C/C++ 包含路径和符号”
?选择“添加外部包含路径...”
?浏览到头文件的位置
?刷新

回答by bugarre

Maybe it is related with KeyAssist bindings.

也许它与 KeyAssist 绑定有关。

If you have tried with content assist:

如果您尝试过使用内容辅助:

Enter into Window > Preferences. Menu "General" -> "Keys"

进入“窗口”>“首选项”。菜单“常规”->“按键”

Inside search for "Template"and set:

在内部搜索“模板”并设置:

Key Binding to -> "Ctrl + Space"

绑定到->“Ctrl + Space”

When: "Editing Test"

时间:“编辑测试”

Image helper Image Menu Key Assist Code Complete

Image helper Image Menu Key Assist Code Complete

回答by koschei

Vim offers this functionality by scanning your #include's (the shortcut is Ctrl-N, or Ctrl-P to search backwards). If you can't find any better solution, one last resort could be looking into eclim, which integrates vim features into Eclipse (or vice-versa), and that's sure to offer this feature.

Vim 通过扫描 #include 来提供此功能(快捷键是 Ctrl-N,或 Ctrl-P 向后搜索)。如果您找不到任何更好的解决方案,最后的方法可能是查看eclim,它将 vim 功能集成到 Eclipse 中(反之亦然),并且肯定会提供此功能。