Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sublime Text 2 - Auto-complete/suggest from other files

Tags:

sublimetext

Say I have 2 files:

foo
bar
baz

and

123
456
f[want autocomplete here]

If I type 1 in the 2nd file, Sublime will suggest 123. But if I type f it wont suggest anything. I want it to suggest foo like it would if I were inside the first file.

It seems like this should be simple (each buffer can autocomplete, so searching all of them can't be so hard) but I haven't been able to find a plugin that does this.

like image 302
noah Avatar asked Jan 31 '12 15:01

noah


People also ask

How do I get auto suggestions in Sublime Text?

By default, Sublime Text will automatically show the completions popup when a user is editing source code or markup, but not within prose in comments, strings or markups. Pressing the Esc key will hide the completions popup. To manually show the completions popup, press Ctrl+Space.

Does Sublime have IntelliSense?

Sublime has autocompletion already and there's no IntelliSense package.

How do you code auto complete?

Invoke type-matching completion Start typing. By default, IntelliJ IDEA displays the code completion popup automatically as you type. If automatic completion is disabled, press Ctrl+Shift+Space or choose Code | Code Completion | Type-Matching from the main menu. If necessary, press Ctrl+Shift+Space once again.


2 Answers

I've implemented the same idea and published it as a package so it can be installed directly from within Sublime with Package Control:

Press ctrl+shift+p (Windows, Linux) or cmd+shift+p (OS X) to open the Command Pallete. Start typing 'install' to select 'Package Control: Install Package', then search for AllAutocomplete and select it.

Code is here: https://github.com/alienhard/SublimeAllAutocomplete

like image 111
alienhard Avatar answered Oct 03 '22 02:10

alienhard


I wrote a plugin that does this:

import sublime_plugin, sublime  class AutocompleteAll(sublime_plugin.EventListener):      def on_query_completions(self, view, prefix, locations):         window = sublime.active_window()         # get results from each tab         results = [v.extract_completions(prefix) for v in window.views() if v.buffer_id() != view.buffer_id()]         results = [(item,item) for sublist in results for item in sublist] #flatten         results = list(set(results)) # make unique         results.sort() # sort         return results 
like image 34
noah Avatar answered Oct 03 '22 02:10

noah