Shortcut key for 'close others'

Things I have tried

Searching through the list of keyboard shortcuts and trying them out. Searching the forum.

What I’m trying to do

Close all other tabs in a tab group - not all other tabs in all tab groups.

Right clicking on a tab in a tab group with more than one tab open has the option to ‘close others’ which closes all the other tabs in the tab group. Is there a shortcut key for this, or some way to do this without using the mouse?

You can set a custom hotkey for this in Settings > Hotkeys.

Thanks, but I would like to close only all other tabs in a tab group. The ‘close all other tabs’ closes all other tabs regardless of tab group.

Got it – whoops, then, I don’t think this is possible with stock Obsidian. There might be a plugin that can help, but I’m not sure.

On which platform are you? Windows or Mac?

It might be possible to achieve this using shortcuts in the operating system, targeting the Obsidian app.

Yeah, I don’t think so either, I just want to make sure before making a feature request.

Linux! There is probably a way to do this with the vimrc support plugin or some kind of script, but digging so far into the internals of Obsidian is beyond my skills.

Hmm… Don’t know any good options there. In Mac you can setup a keyboard shorcut and pick some of the default menus available within Obsidian, like the Close other. (That is if I’m not totally mistaken, and understood some of the answers I found looking for an answer to this request).

I reckon something similar should exist for Linux, as well, but I’m not sure what it’s called, and how that would work.

I’m a bit unsafe today, I think, but the following dataviewjs script closes all other windows in the active tab group, it seems. Any caveats, I really don’t know, but the other windows disappear for sure.

for (let child of app.workspace.activeTabGroup.children) {
  if ( !child.containerEl.className.includes('mod-active') )

Disclaimer: Run at your own risk! :smiley:

Now, how can I attach a query/script like this to a hotkey? Do I really need have an active view open, and insert a Templater javascript template? Or is there another way, I wonder?

Thanks! This is awesome.

Just tried it in the sandbox vault, and sometimes it closes all other tabs in the group and sometimes all but one other tab, and then running it again closes the remaining other tab.

I’ll see if I can combine this with a vimrc obcommand…

The base for this script is the active view, so if that’s not set I reckon it can go a little haywire and close something unexpected. Just something I whipped together for the fun of it, but if it’s useful… :smiley:

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.