Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Open files in same tab or in a new split #81
Similar to Ctrl-p in vim
I often want to replace the current tab with a new file instead of opening in a new tab, then navigating back to the old tab and closing it.
It would also be really nice to hit
This should be possible. Notice that the fuzzy finder view supports splitting commands. So, if you execute
referenced this issue
Jun 25, 2015
referenced this issue
May 11, 2017
To replace tabs from the fuzzy finder menu I've come up with this:
in your init.coffe file
atom.commands.add '.fuzzy-finder atom-text-editor[mini]', 'custom:replace-tab', -> atom.workspace.getActiveTextEditor().destroy() atom.commands.dispatch(@, "core:confirm")
In your keymap file:
It's not ideal but seems to do the trick. And gave me a chance to mess around with the init file. :)
Needs some work on splitted panels. i guess might have a look at it later on.
The above solution is pretty cool, but needs some tweaking.
Can work around, but a proper replace solution is still needed. Destroy and new isn't really ideal.
Nice work figuring this out though!
I made a small tweak to @lewis-fidlers solution. This is pretty close to the behavior I expect in Vim:
If the current file is not saved, then open the searched file in a vertical split. Otherwise, close the current file and 'replace it' with the new searched file.
atom.commands.add '.fuzzy-finder atom-text-editor[mini]', 'custom:replace-tab', -> # you want to open in an empty pane if typeof atom.workspace.getActivePaneItem() is "undefined" atom.commands.dispatch(@, "core:confirm") # current file is saved else if ! atom.workspace.getActivePaneItem().isModified() current = atom.workspace.getActivePaneItem() atom.commands.dispatch(@, "core:confirm") current.destroy() # current file is not saved else atom.commands.dispatch(@, "pane:split-right")
The order of splitting and destroying is kind of weird, but it is the way it is because I was experiencing some weird behavior if I tried to destroy the current pane before opening the new one (I tried core:confirm and pane:split-*, but had weird behavior with both).
I set my keybinding to overwrite the default enter key:
'.fuzzy-finder atom-text-editor[mini]': 'enter': 'custom:replace-tab'
Finally working the way I like!
This works great with a single file inside the tab.
When I've made a split (let's say, one file on the left and one on the right, and I'm currently in the right file), both yours and @lewis-fidlers's solution will close the right split, then open the chosen file in a new tab instead of replacing that split.
Maybe this needs to be updated for newer Atom versions? I'm not familiar enough right now.