Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
paulcsmith opened this issue Mar 6, 2015 · 29 comments
Open

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

paulcsmith opened this issue Mar 6, 2015 · 29 comments
Labels

Comments

@paulcsmith
Copy link

@paulcsmith paulcsmith commented Mar 6, 2015

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
Copy link

@admpsktt admpsktt commented May 1, 2015

👍

@izuzak
Copy link
Member

@izuzak 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
Copy link
Author

@paulcsmith paulcsmith commented 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'
@paulcsmith
Copy link
Author

@paulcsmith paulcsmith commented May 1, 2015

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

@admpsktt
Copy link

@admpsktt admpsktt commented May 2, 2015

❤️

@tonatiuh
Copy link

@tonatiuh tonatiuh commented Nov 6, 2015

Thanks @paulcsmith. That works.

Any news on opening the file in the current tab?

@sarink
Copy link

@sarink sarink commented Nov 7, 2015

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

@bobalazek
Copy link

@bobalazek bobalazek commented Dec 3, 2015

+1

2 similar comments
@rickmed
Copy link

@rickmed rickmed commented Dec 23, 2015

+1

@BigfootN
Copy link

@BigfootN BigfootN commented Jan 15, 2016

+1

@rosenfeld
Copy link

@rosenfeld rosenfeld commented Mar 8, 2016

+1

1 similar comment
@anhari
Copy link

@anhari anhari commented Mar 13, 2016

👍

@bbrock25
Copy link

@bbrock25 bbrock25 commented Mar 20, 2016

👍 this would greatly reduce the clutter in my workspace 😻

@averyvery
Copy link

@averyvery averyvery commented 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.

@andrelevi
Copy link

@andrelevi andrelevi commented Jul 24, 2016

+1 😎

@skidding
Copy link

@skidding skidding commented Jul 29, 2016

+1

@eonist
Copy link

@eonist 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
Copy link

@dimroc dimroc commented Nov 15, 2016

+1

2 similar comments
@nocksock
Copy link

@nocksock nocksock commented Jan 12, 2017

+1

@arcarson
Copy link

@arcarson arcarson commented Feb 13, 2017

+1

@mmarchini
Copy link

@mmarchini mmarchini commented May 20, 2017

+1

@JStans12
Copy link

@JStans12 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
Copy link

@lewis-fidlers 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
Copy link

@JStans12 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
Copy link

@roerjo 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
Copy link

@aguynamedben aguynamedben commented Mar 13, 2018

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

@trusktr
Copy link

@trusktr 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.

@cldwalker
Copy link

@cldwalker cldwalker commented Jul 8, 2019

While @lewis-fidlers and @roerjo solutions work well enough, it did feel hacky to constantly destroy pane items. I found that Atom does natively support opening in the sane pane item with a pending pane item (thanks to @eonist for the tree-view tip). Here's the function (which shouldn't have any split pane issues):

atom.commands.add '.fuzzy-finder atom-text-editor[mini]', 'me:replace-pane-item', ->
  paneItem = atom.workspace.getActivePaneItem()
  # Dispatch with default opening if there are unsaved changes. Do _not_ clobber unsaved changes.
  if paneItem.isModified and paneItem.isModified()
    atom.commands.dispatch(@, "core:confirm")
  else
    # Need to set current pane item to pending in order for Workspace#open to work as expected.
    # I do not use pending pane items for anything else so do not restore original pending item
    atom.workspace.getActivePane().setPendingItem(paneItem)
    selectedUri = atom.packages.getActivePackage('fuzzy-finder').mainModule.projectView.selectListView.getSelectedItem().uri
    # Open with pending to open file in same pane item - https://atom.io/docs/api/v1.38.2/Workspace#instance-open
    atom.workspace.open(selectedUri, {pending: true, searchAllPanes: atom.config.get('fuzzy-finder.searchAllPanes')}).then (editor) ->
      # Disable pending on new editor to avoid unexpected behavior e.g. future file openings replacing current pane item
      editor.terminatePendingState()

I'll be making any future tweaks to this command in my atomfiles. I have the command mapped to cmd-enter so I can choose when to replace a pane item.

Next on my vim/emacs-like wishlist is for the buffer finder to list and autocomplete all files that have been opened, not just current open pane items. If anyone has any tips I'm all ears

@cldwalker
Copy link

@cldwalker cldwalker commented Jul 17, 2019

I did find the recent-files-fuzzy-finder package achieves vim-like navigation to previously opened buffers. Here are my two commands which achieve opening in place for files and previous buffers, along with their keybindings

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
You can’t perform that action at this time.