Skip to content

Instantly share code, notes, and snippets.

@OdatNurd
Created September 19, 2022 03:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save OdatNurd/cdcc99f34182e59fec1092f160b499eb to your computer and use it in GitHub Desktop.
Save OdatNurd/cdcc99f34182e59fec1092f160b499eb to your computer and use it in GitHub Desktop.
Switch to the next or previous file group in Sublime Text
[
// Add to your own custom key bindings file using 'Preferences > Key Bindings'; set the keys as
// desired for your own use.
{ "keys": ["super+t"],
"command": "switch_group",
"args": {"forward": true }
},
{ "keys": ["super+ctrl+t"],
"command": "switch_group",
"args": {"forward": false }
},
]
import sublime
import sublime_plugin
class SwitchGroupCommand(sublime_plugin.WindowCommand):
"""
Switches the focus to either the next or previous file group from the current
one. When forward is true, the focus shifts to the next group, and when false
it goes to the previous group. Going past the "end" of the list of groups
wraps around to the other end.
"""
def run(self, forward=True):
# Alias the window the command is in to make the text shorter
w = self.window
# If we're moving forward, the group goes up by 1; otherwise down by 1
adjustment = 1 if forward else -1
# Add our adjustment to the current group number, and keep it in range of
# the number of groups that exist
new_group = (w.active_group() + adjustment) % w.num_groups()
# Focus the group
w.focus_group(new_group)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment