Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Close Others" command shortcut in Sublime Text 2

Tags:

I am trying to add a shortcut for "Close Others" tabs, but can't seem to find the command, here is what I am trying:

{ "keys": ["super+alt+w"], "command": "close_others" } 

Cmd+Option+W - sort of like Cmd+Option+H in OS X, close all except the current tab, see?

Anyway, close_others doesn't seem to do anything. I have tried close_other_windows, close_other_tabs, nothing works. What is the right command to do that?

And while we're on it, how do you know what commands are available? My next one will be Cmd+Option+Shift+W - "Close Tabs to the Right".

For some improvements in Sublime window management see "Close all tabs, but not the window, in Sublime Text"

Thanks!

like image 760
firedev Avatar asked Mar 13 '13 08:03

firedev


1 Answers

The command is close_others_by_index. Unfortunately, it takes arguments that cannot be passed via a simple key binding.

To make it work, you have to create a plugin. Tools/New Plugin...:

import sublime_plugin  class CloseOthersCommand(sublime_plugin.TextCommand):     def run(self, edit):         window = self.view.window()         group_index, view_index = window.get_view_index(self.view)         window.run_command("close_others_by_index", { "group": group_index, "index": view_index}) 

Save it in Packages/User directory. Then you can add your key binding:

{ "keys": ["super+alt+w"], "command": "close_others" } 

The same is true for "Close tabs to the right". The command is close_to_right_by_index.

The plugin:

import sublime_plugin  class CloseToRightCommand(sublime_plugin.TextCommand):     def run(self, edit):         window = self.view.window()         group_index, view_index = window.get_view_index(self.view)         window.run_command("close_to_right_by_index", { "group": group_index, "index": view_index}) 

The key binding:

{ "keys": ["super+alt+shift+w"], "command": "close_to_right" } 
like image 167
Riccardo Marotti Avatar answered Sep 28 '22 20:09

Riccardo Marotti