How to get current … in Sublime Text

Page loading, please, little wait
Version 0.2.0
Posted —
Last modified —
  1. Overview
  2. Audience
  3. Relevance
  4. Features
  5. Sublime Text console
    1. Console actions
  6. How to get current …
    1. Packages directory
      1. What is it?
      2. What should you do?
      3. Method
      4. Not recommended
    2. Syntax
      1. What is it?
      2. What should you do?
      3. Method
    3. Theme
      1. What is it?
      2. What should you do?
      3. Method
    4. Color scheme
      1. What is it?
      2. What should you do?
      3. Method
    5. Scope
      1. What is it?
      2. What should you do?
      3. Method
      4. Not recommended
    6. Syntax scope
      1. What is it?
      2. What should you do?
      3. Method
  7. External links

1. Overview

Article, how you can to obtain some variable parameters for your Sublime Text. I wrote about the most common variable parameters, that are found in my answers and comments in Stack Overflow.

2. Audience

Sublime Text users:

3. Relevance

This article is relevant for April 2018. In the future, the data in this article may be obsolete.

4. Features

5. Sublime Text console

5.1. Console actions

Example: if you want to know your syntax, $parameter is Syntax; else theme, $parameter is Theme and so on.

  1. open Sublime Text
  2. open file whose $parameter you want to know
  3. place your caret before symbol whose $parameter you want to know

    Caution

    Please, do not confuse caret and mouse pointer.

  4. open Sublime Text console

  5. paste method from $parameter section to Sublime Text console input area → Enter

You should obtain console output, example:

Example Sublime Text console output

6. How to get current …

6.1. Packages directory

6.1.1. What is it?

Packages directoryData/Packages — path, where stored:

  1. “user packages” except “installed packages” in Sublime Text terminology
  2. User folder, where stored user settings

6.1.2. What should you do?

Actions 1, 4, 5.

6.1.3. Method

sublime.packages_path()

Note

That to obtain directory of “installed packages”, use this method:

sublime.installed_packages_path()

6.1.4. Not recommended

In some sources (example) you can read similar answers:

For Sublime 3, the locations are the following:

Windows: %APPDATA%Sublime Text 3,

OS X: ~/Library/Application Support/Sublime Text 3,

Linux: ~/.config/sublime-text-3.

I'm not recommend this, arguments:

  1. it less simple
  2. in new versions of Sublime Text and/or operating systems paths may be change
  3. it doesn't take portable Sublime Text on Windows

6.2. Syntax

6.2.1. What is it?

6.2.2. What should you do?

Actions 1, 2, 4, 5.

6.2.3. Method

view.settings().get('syntax')

6.3. Theme

6.3.1. What is it?

Please, do not confuse theme and color scheme:

  1. color scheme — file, that design your Sublime Text syntaxes; it zone — area of your opened files
  2. theme — file, that design your Sublime Text UI; almost everyone else, that not highlight color scheme

In image below:

Color scheme and theme

Hint

Also, some parameters contains in Preferences.sublime-settings and stTheme files. stTheme highlight and stylize regular expressions and another elements in input areas of your “Find”, “Find in Files” and “Replace panels”.

stTheme

6.3.2. What should you do?

Actions 1, 2, 4, 5.

6.3.3. Method

view.settings().get('theme')

6.4. Color scheme

6.4.1. What is it?

6.4.2. What should you do?

Actions 1, 2, 4, 5.

6.4.3. Method

view.settings().get('color_scheme')

Hint

You can get your another settings, use view.settings().get(). Example: to obtain your current font face, you need view.settings().get('font_face').

6.5. Scope

Caution

“Scope”, “syntax scope”, “syntax type scope” unconventional, not official terms. Please, read links below for additional information.

6.5.1. What is it?

scope syntax scope syntax type scope
source.css meta.property-list.css meta.property-name.css support.type.property-name.css source.css source
text.html.basic source.css meta.property-list.css meta.property-name.css source support.type.property-name.css text.html.basic|text
kira.genius kira.error kira.genius kira

6.5.2. What should you do?

Actions 1, 2, 3, 4, 5.

6.5.3. Method

view.scope_name(view.sel()[0].begin())

6.5.4. Not recommended

In some sources (example) you can read similar answers:

Windows — Ctrl+Alt+Shift+P,

macOS — Ctrl+Shift+P.

I not recommend it, arguments:

  1. Hotkeys conflict; one or more your plugins may use same hotkeys.

6.6. Syntax scope

6.6.1. What is it?

Syntax scope — for syntax: part of any scope before first space symbol. Details read above.

6.6.2. What should you do?

Actions 1, 2, 4, 5.

6.6.3. Method

view.scope_name(0).split()[0]

7. External links