tabnine-sublime icon indicating copy to clipboard operation
tabnine-sublime copied to clipboard

Plugin interferes with built-in snippet functionality

Open OlegSmelov opened this issue 7 years ago • 15 comments

To insert a snippet in Sublime, you type a trigger word and press either Tab or Enter. However, it's not possible to use snippets after installing the plugin because it seems to redefine those keys.

I'd expect snippets to work even when the plugin is installed.

OlegSmelov avatar Nov 09 '18 13:11 OlegSmelov

I came to report the same problem.

Even after dismissing the TabNine suggestions by hitting the escape key, the tab key triggers completions from TabNine instead of my own snippet.

thadin avatar Nov 09 '18 13:11 thadin

Experiencing same issue.

I have a JS snippet with trigger log, which will expand into console.log(...).

Now if I type log, TabNine gives me suggestions, and when I press Tab, first of those suggestions is used.

This is not what I want – I wanna use my snippet with trigger log.

vojto avatar Nov 12 '18 08:11 vojto

As a workaround you can go to Sublime Text -> Preferences -> Package Settings -> TabNine -> Key Bindings (Default) and change tab_nine_leader_key to something other than tab.

I can't find a key binding specifically for snippets, so it looks like snippets are tied to the autocomplete popup. In this case there's no solution I can see, since TabNine needs to replace the autocomplete popup.

If anyone knows a way to detect when there is a snippet with an exact match, I'll reopen the issue.

zxqfl avatar Nov 12 '18 10:11 zxqfl

I've personally never created Sublime Text plugins, but it looks like this plugin is parsing the snippet files itself: https://github.com/shagabutdinov/sublime-snippet-caller/blob/master/snippet_caller.py

Maybe TabNine can do something similar and embed the existing snippets in the custom popup.

As a side note, the snippets aren't that tied to the default autocomplete popup; I've set both setting.auto_complete and setting.tab_completion to false. But snippets still work because the default tab binding ignores those settings and checks for "exact": true.

{ "keys": ["tab"], "command": "insert_best_completion", "args": {"default": "\t", "exact": true} },

thadin avatar Nov 12 '18 14:11 thadin

https://github.com/zxqfl/tabnine-sublime/issues/11#issuecomment-437792343 +1 I have a bp binded for binding.pry Now I have to write bp press tab press cmd+z and then press tab

adis-io avatar Dec 26 '18 09:12 adis-io

Hey @zxqfl, love TabNine. I tried your fix in https://github.com/zxqfl/tabnine-sublime/issues/11#issuecomment-437834398 but it didn't work for me.

command: insert_best_completion {"default": "\t", "exact": false}
plugin rewritten command: tab_nine_substitute

In my Default keybindings for TabNine

    { "keys": [";"], "command": "tab_nine_leader_key", "context": [ { "key": "tab_nine_leader_key_available", "operator": "equal", "operand": true }] },
    { "keys": ["shift+;"], "command": "tab_nine_reverse_leader_key", "context": [ { "key": "tab_nine_reverse_leader_key_available", "operator": "equal", "operand": true }] },

keenahn avatar Jan 20 '19 21:01 keenahn

Another way could be to tell Sublime somehow to use a different shortcut instead of Tab, e.g. Ctrl + Space. Then Ctrl + Space would activate the snippet and Tab would activate TabNine.

jabbalaci avatar Mar 15 '19 00:03 jabbalaci

I was unable to get a different keybinding working for the tabnine leader key, as described in this reply - I tried, but the binding did not change from tab.

But something that is workable for me is to use a keybinding that triggers sublime's built in autocompletion to find a snippet, and then to immediately accept the first one (wanted to continue using a single hotkey press to trigger a snippet):

{ "keys": ["alt+y"], "command": "chain", "args": { "commands": [ ["auto_complete"], ["commit_completion", {"context": [{ "key": "auto_complete_visible" }]}] ] } },

Note that this uses the Chain of Command plugin.

apollokit avatar Jul 24 '19 01:07 apollokit

Well, this makes the whole idea behind this plugin questionable. The completions look like a miracle, but snippets are an important part of my workflow.

kapooostin avatar Jul 24 '19 08:07 kapooostin

Oh, to be clear, I'm using this shortcut for snippets in addition to tab nine autocompletion ("auto_complete" still seems to use sublime's built in autocompletion, which finds my snippets just fine). The inability to remap the tab nine leader key ain't great though.

apollokit avatar Jul 25 '19 19:07 apollokit

I'm in the same camp and struggling to find a workaround for this...

mackermedia avatar Aug 09 '19 18:08 mackermedia

Has there been any update/workarounds on this? I've just installed TabNine to give it a try and it looks pretty neat - but stopping snippets working is a real pain.

IPWright83 avatar May 26 '20 08:05 IPWright83

Doesn't fix the issue, but it is worth noting you can assign keyboard shortcuts to your snippets instead of relying on tab. Sublime Text > Preferences > Key Bindings

{ "keys": ["ctrl+l"], "command": "insert_snippet", "args":
  {"name": "Packages/User/snippets/js-console-log.sublime-snippet"}
},

It would be nice however, to be able to configure certain keywords in TabNine, so that they always appear at the top of the tab completion list. 🙏

danro avatar Jun 14 '20 05:06 danro

Has there been any update/workarounds on this? I've just installed TabNine to give it a try and it looks pretty neat - but stopping snippets working is a real pain.

@apollokit's work around seems to work. I mapped it to shift+tab since I didn't use that keybinding for its default value and it requires less mental remapping than using something completely different. The difficulty is it requires you to have your snippets pretty well memorized. It would be nice to have something more streamlined but TabNine is nice enough to be worth the effort, IMO.

samuelvanderwaal avatar Jul 14 '20 20:07 samuelvanderwaal

Hi all, we've just released a new plugin for sublime that handles this issue. It is still an experiment that is not available for all by default. If you want to try it out contact [email protected] for guidance on how to enable it.

avichay77 avatar Oct 07 '20 06:10 avichay77