“Close Others” command shortcut in Sublime Text 2

时光毁灭记忆、已成空白 提交于 2019-12-03 04:56:33

问题


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!


回答1:


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" }



回答2:


i made a sublime-plugin for that (and for the "Close Other Windows" Functionality)

https://packagecontrol.io/packages/CloseOtherWindows



来源:https://stackoverflow.com/questions/15379860/close-others-command-shortcut-in-sublime-text-2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!