4

I'd like to create a package containing a series of snippets that incorporate user-definable variables. For example, I'd like the user to be able to provide a value for a variable called HOSTNAME and have the snippets include that user's value.

The Sublime Text Unofficial Documentation explains:

Snippets have access to contextual information in the form of environment variables. Sublime Text automatically sets the values of the variables listed below.

You can also add your own variables to provide extra information. These custom variables are defined in .sublime-options files.

I've had no luck finding any information on the syntax for a .sublime-options file, however, and Sublime does not seem to try to read a file with that extension when I save it anywhere under the Packages directory. Is this a typo?

Using a .tmPreferences file seems to do what I'm looking for. Is this the only method of getting user-defined values into a snippet? Is it possible to use a .sublime-settings file?

1 Answer 1

5

The .sublime-options, actually, is the .sublime-settings. .sublime-options were the ST1 files and the docs got outdated, BUT you use the wrong link, you should always check and switch in the sidebar on the left to your version - ST2, ST3.

And to answer your question, you need to put the variables in .tmPreferences as may be seen here

Sign up to request clarification or add additional context in comments.

4 Comments

Thanks, @Vlakarados. Sorry for the incorrect link. The ST2 and ST3 pages list .sublime-options as well though.
@PjDietz as stated below the pages, the docs for this topic are in draft format, I think they simply forgot to update that part :)
@SergeyTelshevsky We really need to remind them to update the document. Besides, using the .tmPreferences method, how could I insert snippet of the current time?
@Jason can't help you with that, usually it's much easier to write a one liner in python than use snippets. The doc is never properly updated, there is this though: sublimetext.info this is the best place for an up to date documentation

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.