Ed Delaire
Ed Delaire

Reputation: 1

Is it possible to take control of sublimetext3 tabs with cmd

Good Day. I am a hobby programmer, and am just looking for creative ways to get things done. In particular, closing a tab or tabs in sublimetext3 through a cmd line method.

The even cooler thing would be, if so, is there a way to decide in cmd which tab to close e.g. 3rd from left/right etc?

In keeping with the idea that this is mostly curiosity and preference than anything else, so creative replies are definitely appreciated as well.

Upvotes: 0

Views: 17

Answers (1)

Keith Hall
Keith Hall

Reputation: 16065

You can execute any command* from the command line, so this is very much possible.

For example, to close the active tab of the most recently used Sublime Text window, you can run subl --command close.

To close a specific tab, for example the 18th tab, which will have index 17 because it is zero-based:

subl --command 'close_by_index {"group": 0, "index": 17}'

(This is assuming bash syntax - for Windows cmd syntax, you may need to do some creative escaping because the command arguments have to be valid JSON and quoted as part of the same argument as the name of the command you want to execute.)

This is exactly the same command that would be run when right-clicking on the tab and picking Close Tab in the context menu. This command can be seen by inspecting Packages/Default/Tab Context.sublime-menu using the built-in View Package File functionality in the Command Palette. You can check this file to see other pre-defined entries like closing all other tabs, or tabs to the right etc.


*: Caveats being if ST is not already running, then it tries to run the command before plugins are loaded.

Upvotes: 2

Related Questions