Skip to content

Instantly share code, notes, and snippets.

@mattst
Last active October 27, 2018 16:23
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 mattst/4747f216e9e8882d5fd88995b39fa34e to your computer and use it in GitHub Desktop.
Save mattst/4747f216e9e8882d5fd88995b39fa34e to your computer and use it in GitHub Desktop.
An ST plugin to move the active buffer's tab left and right on the tab bar.
#
# Name: MoveTabInGroup
# Requirements: Plugin for Sublime Text v2 and v3
# Written by: mattst - https://github.com/mattst
# ST Command: move_tab_in_group
# Arg Required: direction: "left" or "right"
# Description: An ST plugin to move the active buffer's
# tab left and right on the tab bar.
#
import sublime
import sublime_plugin
class MoveTabInGroupCommand(sublime_plugin.WindowCommand):
"""
An ST plugin to move the active buffer's tab left and right on the tab bar.
"""
def run(self, direction):
active_sheet = self.window.active_sheet()
if not active_sheet:
return
group, tab_pos = self.window.get_sheet_index(active_sheet)
num_tabs_in_group = len(self.window.sheets_in_group(group))
if tab_pos < 0 or num_tabs_in_group < 2:
return
elif direction == "left":
new_tab_pos = tab_pos - 1
if new_tab_pos < 0:
new_tab_pos = num_tabs_in_group - 1
elif direction == "right":
new_tab_pos = tab_pos + 1
if new_tab_pos >= num_tabs_in_group:
new_tab_pos = 0
else:
return
self.window.set_sheet_index(active_sheet, group, new_tab_pos)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment