102

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.

As I understand it, the moment I write "pars" I should get the "parseFloat" and "parseInt" options, as in the Chrome developer tools, right?

Thanks!

Community
  • 1
  • 1
ezequiel-garzon
  • 3,047
  • 6
  • 29
  • 33
  • 8
    this 2015: situation hasn't improved. Nothing works out of the box. 8 years old editors have better auto complete. – Muhammad Umer Jun 27 '15 at 04:46
  • See my answer below, @MuhammadUmer. So far it works; out of the box.. and beautiful. – Steve Meisner Jan 09 '17 at 02:34
  • 1
    @SteveMeisner - your answer is discussed here http://meta.stackoverflow.com/q/341163/73226 – Martin Smith Jan 09 '17 at 08:41
  • 1
    I had answered with a mostly "link only" answer and it got snobbed. But here is the fantastic package I've for for JS intellisense/autocompletion: https://github.com/pichillilorenzo/JavaScript-Completions – Steve Meisner Jan 12 '17 at 14:15
  • Just in case someone like me dealing with this problem. This was the reason why I switched to VS Code. It has this wonderful Intellisense feature that works nice also getting autocompletions across JS modules. So far enjoying it. – Sergiy Ostrovsky Mar 14 '17 at 14:22
  • im using vscode as well, but unfortunately it's nowhere near as fast as sublime ( being an electron app vs a native program ) - even just typing text i can feel the input lag is much bigger compared to sublime. But man, vscode's intellisense is the beast. Out of all sublime autocomplete plugins i tried, nothing came close to it, when it comes to displaying and highlighting actually relevant completions at the right time. – Jo Gro Apr 19 '18 at 10:16
  • This 2018: situation hasn't improved. Nothing works out of the box. – Sang Dang Aug 06 '18 at 22:36

7 Answers7

78

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:

As a side note, I'd really recommend installing Package control to 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.

dbn
  • 13,144
  • 3
  • 60
  • 86
  • 1
    Upvoted and accepted based on the wonderful Emmet toolkit! It is mind blowing. It doesn't quite know as nearly as much JS as the Chrome web inspector, but I guess that's not such a bad thing. (After all, I want to enhance my muscle memory.) On the other hand, the work Emmet does for you is amazing! Thanks! – ezequiel-garzon Dec 17 '12 at 20:24
  • 2
    Glad it was helpful. I hope that you end up watching that whole tutorial sequence; there's a lot of good stuff in there. – dbn Dec 18 '12 at 07:02
  • 1
    But it's not free :/ maybe it was earlier. – Jeff P Chacko Mar 25 '16 at 17:29
  • 3
    I feel like that was an ad for the tutsplus site. Maybe it wasn't originally but I'd rather see linked answers not behind paywalls. – dcmbrown May 31 '16 at 20:12
  • heh, yeah, those were all free when I watched 'em. Updating answer to note that these are behind a paywall. – dbn Jun 02 '16 at 21:09
67

Ternjs is a new alternative for getting JS autocompletion. http://ternjs.net/

Sublime Plugin

The most well-maintained Tern plugin for Sublime Text is called '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.

Community
  • 1
  • 1
subhaze
  • 8,815
  • 2
  • 30
  • 33
  • 2
    Crashes ST3. Project isn't maintained. – Chords Jun 11 '15 at 16:38
  • 1
    I've not experienced that, which package are you using? I'm using https://github.com/marijnh/tern_for_sublime – subhaze Jun 12 '15 at 12:10
  • TernJS: Lots of issues like https://github.com/emmetio/sublime-tern/issues/41 and https://github.com/emmetio/sublime-tern/issues/36 and a few others on blogs, etc. Package list shows TernJS and tern_for_sublime. As long as these comments exist to steer people away, I'm happy. Locked up Sublime is no fun. – Chords Jun 12 '15 at 14:19
  • 2
    I would recommend using the one in *the link I provided in the answer* and in my comment. It's still maintained. – subhaze Jun 12 '15 at 14:24
  • Why so salty? TernJS is the first package listed in package manager and it says "TernJS plugin for Sublime Text". Your edited post clarification benefits the community and is appreciated even with the all-too-common stack overflow 'tude. Clearly others have had issues, per the repo issues. – Chords Jun 15 '15 at 01:03
  • 1
    I don't really see that as 'salty' but I did want to point out that your comment was incorrect in saying that the plugin I linked to wasn't maintained. As it has very recent updates on github. – subhaze Jun 17 '15 at 19:27
  • 1
    I've updated the comment to hopefully be less/not salty :/ and while reading these comments hopefully people wont be 'steered away' but in the correct direction. – subhaze Jun 17 '15 at 19:46
  • Until now (Feb,2020) the `tern_for_sublime` is by far the best choice despite all of the issues. Microsoft had recently introduced the `TypeScript` plugin for SublimeText but it is very poor in perfomance and I had to switch back to `TernJs` – Amin Hemati Nik Feb 09 '20 at 11:04
43

As already mentioned, tern.js is a new and promising project with plugins for Sublime Text, Vim and Emacs. I´ve been using TernJS for Sublime for a while and the suggestions I get are way better than the standard ones:

enter image description here

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:

"ternjs": {
    "exclude": ["wordpress/**", "node_modules/**"],
    "libs": ["browser", "jquery"],
    "plugins": {
        "requirejs": {
            "baseURL": "./js"
        }
    }
}

enter image description here

eosterberg
  • 1,422
  • 11
  • 11
  • In the last example I am not getting the 'src' suggestion - I've just installed (Sublime Text 3) and used your project setting. – Rune Jeppesen Jan 12 '15 at 19:05
  • 2
    Any support for ES6 (ES2015) style javascript? – Dan Esparza Sep 27 '15 at 19:03
  • 1
    Yeah, the tern.js project site contains a list of supported ES6 features – eosterberg Sep 27 '15 at 19:07
  • 1
    For what it's worth, you're stating you use "tern for sublime" but it links to the ternJS plugin... Tern for Sublime -> https://packagecontrol.io/packages/tern_for_sublime TernJS -> https://packagecontrol.io/packages/TernJS – subhaze Aug 28 '16 at 22:14
  • I'm surprised you get the selectedIndex attribute, as createTag will return an img HTTP tag. Plus, selectedIndex belongs to a select HTTP tag, NOT to img or its parent element. Would you be so kind of commenting about how do you get those two suggestions? I believe is because you have used them in other files, and not because JsTern has the ability of resolving the createElement call on the run. Suggesting selectedIndex makes no sense nevertheless. – Alex Dec 22 '16 at 02:40
9

There are three approaches

  • Use SublimeCodeIntel plug-in

  • Use CTags plug-in

  • Generate .sublime-completion file manually

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/

Mikko Ohtamaa
  • 82,057
  • 50
  • 264
  • 435
7

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.

Furthermore, it offers smart javascript autocomplete (compared to my other plugin JavaScript Completions), real-time errors, code refactoring and also a lot of features about creating, developing and managing javascript projects.

See the Wiki to know all the features that it offers!

An introduction to this plugin could be found in this css-tricks.com article: Turn Sublime Text 3 into a JavaScript IDE

Just some quick screenshots:

Lorenzo Pichilli
  • 2,896
  • 1
  • 27
  • 50
  • 1
    Hi Lorenzo. I am curious about your project, but I'd like to which options I have in terms of customizing the completions. Basically I want to have suggestions like `docu` > `document`, `document.que` > `document.querySelector` and so forth, but never a full function call with arguments and multiple lines like `arr.forEa` > `arr.forEach((object,index,array) => { /* newline */ });`, if that makes sense. Could I disable that with Javascript Enhancements without having to manually editing all the completion files? I've disabled all completions now since I'm a little obsessive with my structure. – ViggoV Mar 22 '19 at 09:02
2

As of today (November 2019), Microsoft's TypeScript plugin does what the OP required: https://packagecontrol.io/packages/TypeScript.

Michał Jabłoński
  • 1,129
  • 1
  • 13
  • 15
1

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 jQuery plugins.

See my answer on this thread for more details.

Community
  • 1
  • 1
Alexander Rechsteiner
  • 5,694
  • 5
  • 34
  • 47