Help Setting Keybinding for Close Tabs to the Right


I dove into the source code to find the name of the Close Tabs to the Right event, and I believe it should be:


However, when I add the following to my user keymap file, I am not able to successfully activate the event.

  'alt-shift-r': 'tabs:close-tabs-to-right'

Are the tab events not able to be activated?


Tabs commands are not registered at the workspace level but on the tab-bar, that’s why they can register a context-menu but you cannot register a keybinding.

One problem with registering this kind of command at the workspace level when in a view is that you’ll never know which view should receive the command (there’s one tab-bar per pane) except when you give the focus to the tab-bar.

My suggestion is to create you own command in your file to trigger that event on the active tab-bar, something like:

atom.workspaceView.command 'tabs:close-tabs-to-right', ->

With that you can know set a keybinding for that command.


Thanks for that. I see now though that the closeTabsToRight() function is literally looking for the ‘.right-clicked’ selector to decide the active tab.

So, I think I should just rewrite the closeTabsToRight function in my init file.



Weird, I tried atom.workspaceView.getActivePaneView().find('.tab-bar').trigger('tabs:close-tabs-to-right') from a console at work and it properly removed the tabs. I guess the fact I had right-clicked in a tab prior to the console test had lead me to think it would work.

You can also put a class to the tab when triggering a command.


Yeah, I had been thinking it would be bad to muck with marking things as right-clicked without actually having performed any mouse actions, but I ended up doing just that. I added the following to my

atom.workspaceView.command 'tabs:close-tabs-to-right', ->
  tabsBar = atom.workspaceView.getActivePaneView().find('.tab-bar')
  active = tabsBar.find('.active').addClass('right-clicked')

Thanks for your help.


I updated this to be Atom 1.0 API-compatible (it had some deprecation notices). New code:

atom.commands.add 'atom-workspace', 'custom:close-other-tabs', ->
  activePaneView = atom.views.getView(atom.workspace.getActivePane())
  tabsBar = activePaneView.querySelector('.tab-bar')
  activeTab = tabsBar.querySelector('.active')
  atom.commands.dispatch(tabsBar, 'tabs:close-other-tabs')


Oh, also I modified it to close ALL other tabs, not only the ones to the right.


Good news! It appears that recent versions of Atom expose this setting directly to keymaps.

So, this now works: in your custom keymap.cson

  'alt-shift-r': 'tabs:close-tabs-to-right'

Which is awesome! Hope that helps folks in the future. :slight_smile: