Sublime Forum

Change the order of file tabs via the API?

#1

Currently, I drag and drop file tabs when I want to reorder them. As a keyboard freak I find this somewhat inconvenient, though. Is there an API that could help me reorder tabs in a mouse-free fashion, via my own programmed keyboard shortcuts to drag/drop tabs?

1 Like

#2

Even though it should be a core feature, you might want to try https://packagecontrol.io/packages/MoveTab?

3 Likes

#3

Thank you that plugin did the job, only modulo choosing my own keybindings.

For those curious, I’m copy-pasting the most relevant lines of code from within the implementation of the MoveTab plugin, that show which parts of the API are used (triple ### comment is mine, else is author’s) (please don’t scold me for breaking some licence):

class MoveTabCommand(sublime_plugin.WindowCommand):
	def run(self, position):
		view = self.window.active_view()
		(group, index) = self.window.get_view_index(view)
		if index < 0:
			return
		count = len(self.window.views_in_group(group))

		### (computation of final integer-valued "index" from
        ### string-valued "position" argument and from "count"
        ### went here...)

		# Avoid flashing tab when moving to same index
		if position == index:
			return

		self.window.set_view_index(view, group, position)
		self.window.focus_view(view)
1 Like