Sublime Forum

Command 'close' should behave like clicking the 'X' on a tab

#1

clicking the X leaves me on the previous tab in the row
command ‘close’ pops the current tab off of the stack and leaves me on the previously selected tab.
I bind cmd-w to command ‘close’ and i’d like it to behave exactly like clicking the ‘X’ on the tab does.
the reference here doesn’t mention any params i can pass to the command: docs.sublimetext.info/en/latest/ … mands.html

Is it possible command ‘close’ could add optional params to achieve this?

0 Likes

#2

Is there any way to do this? Closing and then going to some previous tab that I didn’t want to see really bugs me, especially when I want to close a bunch of tabs in a row.

0 Likes

#3

Hey, registered to request this but instead I’ll bump this old thread. The stack-based closing is very unpredictable to me compared to always moving to the right, and is unhelpful when I’m trying to close a lot of my old tabs. Often I just end up closing all my tabs and manually re-opening the few I wanted to keep open :cry: I haven’t seen an option or keybinding to change this, unlike with ctrl+tab which you can rebind from “next_view_in_stack” to “next_view”. Thanks and take care!

0 Likes

#4

You could probably write a small plugin to do this. You could try using the on_close listener to grab the current view, and get the “next” view based on that.

0 Likes

#5

I do this too… it’s really ****ing annoying. :frowning::frowning:

0 Likes

#6

Save this as commands.py in your User package.

[code]import sublime_plugin

class PrevViewCloseCommand(sublime_plugin.WindowCommand):

def run(self):
    view = self.window.active_view()
    group, index = self.window.get_view_index(view)
    if index == 0:
        new_index = 1
    else:
        new_index = index - 1
    views = self.window.views_in_group(group)
    self.window.run_command('close')
    try:
        self.window.focus_view(views[new_index])
    except IndexError:
        pass

[/code]

And add this to your user keymap:

{ "keys": "ctrl+w"], "command": "prev_view_close" },
0 Likes

#7

Hey schlamer, forgot to do this earlier but thanks a lot! Works great. I ended up changing it to:

[code]import sublime_plugin

class PrevViewCloseCommand(sublime_plugin.WindowCommand):
def run(self):
view = self.window.active_view()
group, index = self.window.get_view_index(view)
self.window.run_command(‘close’)
views = self.window.views_in_group(group)
if index >= len(views):
index = index - 1
self.window.focus_view(views[index])[/code]

0 Likes