Home Download Buy Blog Forum Support

Autocomplete/snippet conflict

Autocomplete/snippet conflict

Postby GarethAdams on Tue Mar 13, 2012 2:48 pm

I'm having issues with autocompletion in Sublime, and I want to check whether the problem is that I'm still stuck in a TextMate mindset or whether it's actually an interface issue.

The problem is that autocomplete and snippet completion are both bound to <Tab> but often conflict. As a simple example, in a Ruby document:

Code: Select all

gives me the following code, with the cursor at the indicated point:

Code: Select all
    def run❚

Now, in most places in the document, hitting <Tab> at the current cursor position would autocomplete `run` to `running_process` (assuming that phrase is the closest available match, which in this case it is). But because I'm still in "snippet mode", the <Tab> actually skips me to the method body:

Code: Select all
    def run

There seems to be no way to choose indicate to Sublime that I want to use autocomplete at that point. In Textmate this wasn't an issue because <Tab> was reserved for snippets and <Esc> was the autocomplete trigger - which makes sense to me, because two features which might be available at the same time shouldn't share the same key.

Is there a way to change one of these triggers to a different key, or do I need to change how I'm thinking somehow?
Posts: 1
Joined: Tue Mar 13, 2012 2:31 pm

Re: Autocomplete/snippet conflict

Postby agibsonsw on Tue Mar 13, 2012 2:58 pm

Changing the file setting auto_complete_with_fields to true would enable you to complete an auto-completion/snippet while within a snippet.

Code: Select all
   // By default, auto complete will commit the current completion on enter.
   // This setting can be used to make it complete on tab instead.
   // Completing on tab is generally a superior option, as it removes
   // ambiguity between committing the completion and inserting a newline.
   "auto_complete_commit_on_tab": false,

   // Controls if auto complete is shown when snippet fields are active.
   // Only relevant if auto_complete_commit_on_tab is true.
   "auto_complete_with_fields": false,

You may need to press Ctrl-Space to display the completions list, and then use Enter (rather than Tab) to select one of the new completions.

Alternatively, having typed 'run' and Tab, press Escape to escape from the snippet fields - then Tab (once or twice) might select 'running_thing'.
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
Posts: 901
Joined: Fri Jan 27, 2012 9:11 pm

Re: Autocomplete/snippet conflict

Postby askeeve on Mon Sep 09, 2013 3:03 pm

I seem to be having a different kind of conflict.
I have a snippet with:
Code: Select all
and an auto-complete:
Code: Select all
{ "trigger": "@Break($1)", "contents": "Break($1)" },

When I type:
Code: Select all
the auto-complete window comes up and then hitting tab chooses the auto complete over the snippet. The docs say:
Snippets will always win if the current prefix matches their tab trigger exactly.
which is the case, but the Snippet seems to be losing to the auto-complete.

Other than turning auto-complete off or increasing the delay on the auto-complete window, no combination of the preferences regarding tab-completion seem to fix this problem for me. I realize it's a bit of a weird case but I'd really rather not change the tabTrigger for my snippet if I can avoid it. I feel like I must be missing something pretty obvious but for the life of me I can't figure it out. Any suggestions?
Posts: 51
Joined: Wed Apr 18, 2012 1:33 pm

Return to General Discussion

Who is online

Users browsing this forum: Exabot [Bot], Google [Bot] and 30 guests