Open files in same tab or in a new split #81

Open
paulcsmith opened this Issue Mar 6, 2015 · 27 comments

Comments

Projects
None yet
@paulcsmith

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 <Ctrl-v> in fuzzy finder to open the file in a new vertical split and <Ctrl-S> for a horizontal split.

@50Wliu 50Wliu added the enhancement label Mar 6, 2015

@admpsktt

This comment has been minimized.

Show comment
Hide comment

admpsktt commented May 1, 2015

👍

@izuzak

This comment has been minimized.

Show comment
Hide comment
@izuzak

izuzak May 1, 2015

Member

It would also be really nice to hit <Ctrl-v> in fuzzy finder to open the file in a new vertical split and <Ctrl-S> for a horizontal split.

This should be possible. Notice that the fuzzy finder view supports splitting commands. So, if you execute pane:split-right while a specific file is selected in the fuzzy finder -- that file will be opened in a split view. The only thing left to do is that you customize your keybindings so that it triggers pane:split-right when you hit <Ctrl-v> (see this). By default, that command triggers on cmd-k right (on OSX), see this.

@paulcsmith @admpsktt Does that help?

Member

izuzak commented May 1, 2015

It would also be really nice to hit <Ctrl-v> in fuzzy finder to open the file in a new vertical split and <Ctrl-S> for a horizontal split.

This should be possible. Notice that the fuzzy finder view supports splitting commands. So, if you execute pane:split-right while a specific file is selected in the fuzzy finder -- that file will be opened in a split view. The only thing left to do is that you customize your keybindings so that it triggers pane:split-right when you hit <Ctrl-v> (see this). By default, that command triggers on cmd-k right (on OSX), see this.

@paulcsmith @admpsktt Does that help?

@paulcsmith

This comment has been minimized.

Show comment
Hide comment
@paulcsmith

paulcsmith May 1, 2015

@izuzak Thank you! This worked brilliantly!

For others that want this behavior here are my keybindings

'.fuzzy-finder atom-text-editor[mini]':
  'ctrl-v': 'pane:split-right'
  'ctrl-s': 'pane:split-down'

@izuzak Thank you! This worked brilliantly!

For others that want this behavior here are my keybindings

'.fuzzy-finder atom-text-editor[mini]':
  'ctrl-v': 'pane:split-right'
  'ctrl-s': 'pane:split-down'
@paulcsmith

This comment has been minimized.

Show comment
Hide comment
@paulcsmith

paulcsmith May 1, 2015

The only thing missing is opening a file in the same tab. I don't see commands for that :S

The only thing missing is opening a file in the same tab. I don't see commands for that :S

@admpsktt

This comment has been minimized.

Show comment
Hide comment

admpsktt commented May 2, 2015

❤️

@tonatiuh

This comment has been minimized.

Show comment
Hide comment
@tonatiuh

tonatiuh Nov 6, 2015

Thanks @paulcsmith. That works.

Any news on opening the file in the current tab?

tonatiuh commented Nov 6, 2015

Thanks @paulcsmith. That works.

Any news on opening the file in the current tab?

@sarink

This comment has been minimized.

Show comment
Hide comment
@sarink

sarink Nov 7, 2015

+1 for a shortcut to open files in the current tab

sarink commented Nov 7, 2015

+1 for a shortcut to open files in the current tab

@bobalazek

This comment has been minimized.

Show comment
Hide comment

+1

@rickmed

This comment has been minimized.

Show comment
Hide comment

rickmed commented Dec 23, 2015

+1

@BigfootN

This comment has been minimized.

Show comment
Hide comment

+1

@rosenfeld

This comment has been minimized.

Show comment
Hide comment

+1

@anhari

This comment has been minimized.

Show comment
Hide comment

anhari commented Mar 13, 2016

👍

@bbrock25

This comment has been minimized.

Show comment
Hide comment
@bbrock25

bbrock25 Mar 20, 2016

👍 this would greatly reduce the clutter in my workspace 😻

👍 this would greatly reduce the clutter in my workspace 😻

@averyvery

This comment has been minimized.

Show comment
Hide comment
@averyvery

averyvery Apr 1, 2016

Also 👍ing this, holding shift-cmd-t or something like that replace a current buffer/tab with the new file would be awesome.

Also 👍ing this, holding shift-cmd-t or something like that replace a current buffer/tab with the new file would be awesome.

@andrelevi

This comment has been minimized.

Show comment
Hide comment

+1 😎

@skidding

This comment has been minimized.

Show comment
Hide comment

+1

@eonist

This comment has been minimized.

Show comment
Hide comment
@eonist

eonist Aug 5, 2016

Opening a file from fuzzy-finder into the current selected tab would be awesome! After a day of work i'm left with 40++ tabs to close because I use the fuzzy-finder to navigate files. Atom fixed this with the tree-view, now its time to fix this for Fuzzy-Finder, no?

eonist commented Aug 5, 2016

Opening a file from fuzzy-finder into the current selected tab would be awesome! After a day of work i'm left with 40++ tabs to close because I use the fuzzy-finder to navigate files. Atom fixed this with the tree-view, now its time to fix this for Fuzzy-Finder, no?

@dimroc

This comment has been minimized.

Show comment
Hide comment

dimroc commented Nov 15, 2016

+1

@nocksock

This comment has been minimized.

Show comment
Hide comment

+1

@arcarson

This comment has been minimized.

Show comment
Hide comment

+1

@mmarchini

This comment has been minimized.

Show comment
Hide comment

+1

@JStans12

This comment has been minimized.

Show comment
Hide comment
@JStans12

JStans12 Aug 3, 2017

I have the tabs plugin turned off any only use fuzzy finder to move between files. Tabs still build up in the background and eventually make atom unbearably slow. This feature would greatly improve my workflow.

JStans12 commented Aug 3, 2017

I have the tabs plugin turned off any only use fuzzy finder to move between files. Tabs still build up in the background and eventually make atom unbearably slow. This feature would greatly improve my workflow.

@lewis-fidlers

This comment has been minimized.

Show comment
Hide comment
@lewis-fidlers

lewis-fidlers Aug 10, 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:

'.fuzzy-finder atom-text-editor[mini]':
  'ctrl-v': 'pane:split-right'
  'ctrl-s': 'pane:split-down'
  'alt-enter': 'custom:replace-tab'

alt-enter will now close the tab you are in and open the one selected in the fuzzy finder.

It's not ideal but seems to do the trick. And gave me a chance to mess around with the init file. :)

Edit:

Needs some work on splitted panels. i guess might have a look at it later on.

lewis-fidlers commented Aug 10, 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:

'.fuzzy-finder atom-text-editor[mini]':
  'ctrl-v': 'pane:split-right'
  'ctrl-s': 'pane:split-down'
  'alt-enter': 'custom:replace-tab'

alt-enter will now close the tab you are in and open the one selected in the fuzzy finder.

It's not ideal but seems to do the trick. And gave me a chance to mess around with the init file. :)

Edit:

Needs some work on splitted panels. i guess might have a look at it later on.

@JStans12

This comment has been minimized.

Show comment
Hide comment
@JStans12

JStans12 Aug 10, 2017

The above solution is pretty cool, but needs some tweaking.

  • have 2 panes open with only 1 tab in each
  • 'custom:replace-tab' in the 2nd pane
  • the 2nd pane is destroyed and a new tab is opened in the 1st pane

Can work around, but a proper replace solution is still needed. Destroy and new isn't really ideal.

Nice work figuring this out though!

JStans12 commented Aug 10, 2017

The above solution is pretty cool, but needs some tweaking.

  • have 2 panes open with only 1 tab in each
  • 'custom:replace-tab' in the 2nd pane
  • the 2nd pane is destroyed and a new tab is opened in the 1st pane

Can work around, but a proper replace solution is still needed. Destroy and new isn't really ideal.

Nice work figuring this out though!

@roerjo

This comment has been minimized.

Show comment
Hide comment
@roerjo

roerjo Oct 27, 2017

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!

EDIT:
This method does seem to break if you only single click an item on the Project panel and attempt to perform a search from that 'preview' file.

roerjo commented Oct 27, 2017

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!

EDIT:
This method does seem to break if you only single click an item on the Project panel and attempt to perform a search from that 'preview' file.

@aguynamedben

This comment has been minimized.

Show comment
Hide comment
@aguynamedben

aguynamedben Mar 13, 2018

+1 from anybody coming from Emacs, where there are no tabs and you just switch buffers all day with a finder

+1 from anybody coming from Emacs, where there are no tabs and you just switch buffers all day with a finder

@trusktr

This comment has been minimized.

Show comment
Hide comment
@trusktr

trusktr May 27, 2018

@roerjo

I made a small tweak to @lewis-fidlers solution. This is pretty close to the behavior I expect in Vim:

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.

trusktr commented May 27, 2018

@roerjo

I made a small tweak to @lewis-fidlers solution. This is pretty close to the behavior I expect in Vim:

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment