Sublime Forum

How to obtain the current scope under the cursor

#1

I am trying to learn how to write plug-ins in Sublime Text 2 and now having a little issue beyond my current knowledge.

How do I get the scope of the current text at the edit cursor?.
The same text that can be seen on the Status bar when you press Ctrl+Alt+Shift+P

0 Likes

#2

Thanks for the ⌘-⌥-P trick; that answered a question I had. What you’re looking for is here: Any way to capture the current theme selector to clipboard?

2 Likes

#3

Thank you, looks like the answer to my problem is;

in the ctrl+’ key (show console) i can type…

print (view.syntax_name(view.sel()[0].b))

gives me what I want

3 Likes

#4

This has changed in the latest version of Sublime text to

print (view.scope_name(view.sel()[0].b))
2 Likes

#5

As this thread has already been revived, here is my addition:
You could also use a plugin like ScopeHunter, which allows for a much more comfortable scope selection.

2 Likes