Sublime Forum

Default auto-complete list?

#1

Hi, I have a question that’s probably pretty easy, but has been bugging me for a few days.I was unable to find anything like this in the forums about this.
I write a lot of SQL (lots of uppercase keywords), so auto-complete is a lifesaver. However, these keywords only auto-complete when they are already present in the document, so I need to type each of those keywords once before they;ll show up. I was wondering if there was a way to define a default universal auto-complete keyword list that would apply to all documents, rather than just pulling from the current document, so that I can be even more efficient (lazier) with my typing.

Thanks

0 Likes

#2

readthedocs.org/docs/sublime-tex … tions.html

0 Likes

#3

So let me get this straight. You can define completions through a JSON .sublime-completions file.
For my purposes, the contents would be pretty simple.

{
        "scope": "text.html - source - meta.tag, punctuation.definition.tag.begin",

        "completions":
        
                "SELECT",
                "FROM",
                "INSERT",
                "JOIN"
        ]
}

The header part confuses me though. What is “scope”? Is that where the completions are applied? If so, what would I set it to to apply to all SQL files? test.sql? What does the rest of it (source - meta.tag, punctuation.definition.tag.begin) mean? Also, where would I put the file?

Sorry for all the questions. The documentation is sparse on this topic.

Thanks.

0 Likes

#4

You need something like one of the following:

[code] “scope”: “source.sql”,

“scope”: “source.sql - string.quoted.double.sql”,

“scope”: “source.sql - string.quoted.double.sql, - string.quoted.single.sql”,
“scope”: “source.sql - string.quoted.double.sql - string.quoted.single.sql”,
“scope”: “source.sql - string.quoted.double.sql, source.sql - string.quoted.single.sql”,[/code]
I’m sure the first two are okay, but I’m not 100% of the other three alternatives - perhaps experiment :wink:

Basically, you’re specifying that the completions only apply to .sql files, but not within quoted text.

You can store the file pretty much anywhere in your Packages folder, but User is generally the best place - so you can find it later, and it won’t interfere with anything else. You can also name it anything, but it must have the extension ‘sublime-completions’.

0 Likes

#5

This version works for me:

"scope": "source.sql - string.quoted.double.sql - string.quoted.single.sql",

You could even save the following as ‘SELECT.sublime-snippet’ in your User folder.

<snippet> <content><![CDATA[SELECT ${1} FROM ${2} WHERE ${3};$0]]></content> <!-- Optional: Set a tabTrigger to define how to trigger the snippet --> <tabTrigger>SELECT</tabTrigger> <!-- Optional: Set a scope to limit where the snippet will trigger --> <scope>source.sql - string.quoted.double.sql - string.quoted.single.sql</scope> </snippet>
Start typing SELECT and then press Tab to complete the other parts of the statement, pressing tab to move between fields. Although… I’m not sure that it will save you a lot of time :sunglasses:

0 Likes

#6

Oh wow! Thanks a lot agibsonsw. That works perfectly. The snippet idea is pretty nifty too. Maybe in the future I’ll find a good use for something like that.

0 Likes

#7

No problem. You could put spaces after your completions, "SELECT ", as they’re always followed by a space anyway :wink:

0 Likes

#8

For your later consideration :smiley: the following snippet is more useful. It is triggered from the word ‘left’ and helps you complete the basic structure for a LEFT (OUTER) JOIN:

<snippet> <content><![CDATA[SELECT ${1:table1}.${2:field1}, ${3:table2}.${4:field2} FROM ${1} AS ${5:tbl1_alias} LEFT JOIN ${3} AS ${6:tbl2_alias} ON ${5}.${7:join_fld} = ${6}.${7};$0]]></content> <tabTrigger>LEFT</tabTrigger> <scope>source.sql - string.quoted.double.sql - string.quoted.single.sql</scope> </snippet>
It will still need to be edited afterwards, but at least the basic structure will be in place quickly.

As an exercise (home work!) you can create one for RIGHT as well. Andy.

0 Likes