Created
September 19, 2022 03:39
-
-
Save OdatNurd/cdcc99f34182e59fec1092f160b499eb to your computer and use it in GitHub Desktop.
Switch to the next or previous file group in Sublime Text
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Show hidden characters
[ | |
// 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 } | |
}, | |
] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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