Javascript 在 Sublime Text 下获得完整的 JS 自动补全
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13661462/
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
Getting full JS autocompletion under Sublime Text
提问by ezequiel-garzon
I just installed the Sublime Text under Windows Vista, and even following the advice given in this post, namely to explicitly set View > Syntax > JavaScript > JavaScript, I only see suggestions based on what I have previously typed. I even installed the SublimeCodeIntel plug-in, to no avail.
我刚刚在 Windows Vista 下安装了 Sublime Text,甚至遵循了这篇文章中给出的建议,即明确设置View > Syntax > JavaScript > JavaScript,我只能看到基于我之前输入的内容的建议。我什至安装了SublimeCodeIntel 插件,但无济于事。
As I understand it, the moment I write "pars" I should get the "parseFloat" and "parseInt" options, as in the Chrome developer tools, right?
据我了解,在我编写“pars”的那一刻,我应该得到“parseFloat”和“parseInt”选项,就像在 Chrome 开发人员工具中一样,对吧?
Thanks!
谢谢!
采纳答案by dbn
Suggestions are (basically) based on the text in the current open file and any snippets or completions you have defined (ref). If you want more text suggestions, I'd recommend:
建议(基本上)基于当前打开文件中的文本以及您定义的任何片段或完成(ref)。如果你想要更多的文字建议,我建议:
- Adding your own snippets for commonly used operations.
- Adding your own completions for common words.
- Adding other people's snippetsthrough Package Control.
- You can find even more snippets on github.
- Use Zen coding(available through Package Control) or Emmet.
- There are also various packages that adjust the way code completion works. I love SublimeCodeIntel, but check out other answers to this question for more options.
- 为常用操作添加您自己的片段。
- 添加您自己的常用词补全。
- 通过Package Control添加其他人的片段。
- 您可以在 github 上找到更多片段。
- 使用Zen 编码(可通过Package Control 获得)或Emmet。
- 还有各种包可以调整代码完成的工作方式。我喜欢SublimeCodeIntel,但请查看此问题的其他答案以获取更多选项。
As a side note, I'd really recommend installing Package controlto take full advantage of the Sublime community. Some of the options above use Package control. I'd also highly recommend the tutsplus Sublime tutorial videos, which include all sorts of information about improving your efficiency when using Sublime.
作为旁注,我真的建议安装 Package control以充分利用 Sublime 社区。上面的一些选项使用包控制。我还强烈推荐tutsplus Sublime 教程视频,其中包含有关在使用 Sublime 时提高效率的各种信息。
回答by subhaze
Ternjs is a new alternative for getting JS autocompletion. http://ternjs.net/
Ternjs 是一种让 JS 自动完成的新选择。http://ternjs.net/
Sublime Plugin
崇高插件
The most well-maintained Tern plugin for Sublime Text is called 'tern_for_sublime'
Sublime Text 维护得最好的 Tern 插件叫做“tern_for_sublime”
There is also an older plugin called 'TernJS'. It is unmaintained and contains several performance related bugs, that cause Sublime Text to crash, so avoid that.
还有一个名为'TernJS'的旧插件。它是无人维护的并且包含几个与性能相关的错误,这些错误会导致 Sublime Text 崩溃,所以要避免这种情况。
回答by eosterberg
As already mentioned, tern.jsis a new and promising project with plugins for Sublime Text, Vim and Emacs. I′ve been using TernJS for Sublimefor a while and the suggestions I get are way better than the standard ones:
如前所述,tern.js是一个有前途的新项目,其中包含适用于 Sublime Text、Vim 和 Emacs 的插件。我已经将TernJS 用于 Sublime一段时间了,我得到的建议比标准的要好得多:


Tern scans all .js files in your project. You can get support for DOM, nodejs, jQuery, and more by adding "libs" in your .sublime-project file:
Tern 扫描项目中的所有 .js 文件。您可以通过在 .sublime-project 文件中添加“libs”来获得对 DOM、nodejs、jQuery 等的支持:
"ternjs": {
"exclude": ["wordpress/**", "node_modules/**"],
"libs": ["browser", "jquery"],
"plugins": {
"requirejs": {
"baseURL": "./js"
}
}
}


回答by Mikko Ohtamaa
There are three approaches
有三种方法
Use SublimeCodeIntel plug-in
Use CTags plug-in
Generate .sublime-completion file manually
使用 SublimeCodeIntel 插件
使用 CTags 插件
手动生成 .sublime-completion 文件
Approaches are described in detail in this blog post (of mine): http://opensourcehacker.com/2013/03/04/javascript-autocompletions-and-having-one-for-sublime-text-2/
这篇博文(我的)中详细描述了方法:http: //opensourcehacker.com/2013/03/04/javascript-autocompletions-and-have-one-for-sublime-text-2/
回答by Lorenzo Pichilli
I developed a new plugin called JavaScript Enhancements, that you can find on Package Control. It uses Flow(javascript static type checker from Facebook) under the hood.
我开发了一个名为JavaScript Enhancements的新插件,您可以在Package Control上找到它。它在底层使用Flow(来自 Facebook 的 javascript 静态类型检查器)。
Furthermore, it offers smart javascript autocomplete(compared to my other plugin JavaScript Completions), real-time errors, code refactoringand also a lot of featuresabout creating, developing and managing javascript projects.
此外,它提供了智能的JavaScript自动完成(相对于我的其他插件的JavaScript完井),实时错误,代码重构,也有很多的功能有关创建,发展和管理的JavaScript项目。
See the Wikito know all the features that it offers!
查看Wiki了解它提供的所有功能!
An introduction to this plugin could be found in this css-tricks.comarticle: Turn Sublime Text 3 into a JavaScript IDE
这个插件的介绍可以在这篇css-tricks.com文章中找到:Turn Sublime Text 3 into a JavaScript IDE
Just some quick screenshots:
只是一些快速截图:






回答by Micha? Jab?oński
As of today (November 2019), Microsoft's TypeScript plugindoes what the OP required: https://packagecontrol.io/packages/TypeScript.
截至今天(2019 年 11 月),微软的TypeScript 插件完成了 OP 的要求:https: //packagecontrol.io/packages/TypeScript。
回答by Alexander Rechsteiner
Check if the snippets have <tabTrigger>attributes that start with special characters. If they do, they won't show up in the autocomplete box. This is currently a problem on Windows with the available jQueryplugins.
检查片段是否具有<tabTrigger>以特殊字符开头的属性。如果他们这样做,他们将不会出现在自动完成框中。这是当前 Windows 上可用jQuery插件的一个问题。
See my answer on this threadfor more details.
有关更多详细信息,请参阅我在此线程上的回答。

