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

[Feature Request] Go to currently opened buffer #39

Open
luiz00martins opened this issue Dec 7, 2022 · 4 comments
Open

[Feature Request] Go to currently opened buffer #39

luiz00martins opened this issue Dec 7, 2022 · 4 comments

Comments

@luiz00martins
Copy link

As an example, in the setup below, I have a couple of buffers opened: init.vim, mappings.lua (in the second tab), plugins_portable.lua, and plugins_complete.lua (in the first tab). init.vim is currently focused.

image

If I press Enter in mappings.lua, it'll open it in the current window, overriding init.vim. Same for any other buffer. It'll open the buffer in the current window focused (which happens to be init.vim).

My feature request, is that I could press a key (perhaps g), and I could go to that buffer's window if it's already opened. In the example above, pressing g on mapping.lua would jump to the second window, as it's already opened there. Pressing g on plugins_portable.lua would jump to the first tab, first window (where it's currently opened), etc.

This would make navigating between currently opened buffers very convenient.

@luiz00martins
Copy link
Author

As a sidenote: Another way to implement this would be to not add a new keybind, but instead make Enter respect whatever switchbuf option the user currently has set.

@jeff-dh
Copy link
Contributor

jeff-dh commented Dec 8, 2022

Just added that feature to my refactored branch:

https://github.com/jeff-dh/expJABS.nvim

Exactly how you described it. Hit 'g' and it'll take you to a(!) window that has the file open (I assume it's always the window with the lowest window id). I decided to take that optoins, because I often want to open a file a second time in a second window and that would not be possible if we would "overload" Enter.

This is really just straight forward implemented without reasoning about it, I'll think about it for a little while, maybe I'll have some more ideas about it (sorting open buffers first?, S-Enter to force open a file a second time or to switch to it?)

Notice: that branch is an experimental refactored fork of JABS. It should be backwards compatible and seems to work but is only tested in a nut shell and has no documentation yet, therefor some nice new features (sorting buffers, restoring deleted buffers, help popup,... ;) If you're having any issues (including issues not related to this issue) let me now!.

PS: position = 'corner' is not the default anymore. If you want to have JABS in the bottom right corner, you have to configure it ( position = {'right', 'bottom'})

@jeff-dh
Copy link
Contributor

jeff-dh commented Dec 8, 2022

I did some minor improvements and I think that's now what you want.

By default the switchTo command (goto is a lua keyword...) is mapped to <S-CR>. If it can't find a window showing the selected buffer it will call the open command.

With the following config you should get exactly what you want I guess:

-- uninstall regular jabs and install expJABS
-- use 'matbme/JABS.nvim'
use {'jeff-dh/expJABS.nvim', branch = 'expJABS'}

--config
require('jabs').setup{
    sort_mru = true, -- if you don't like sorting by most recently used disable it
    position = {'right', 'bottom'},

    keymap = {
        jump = '<S-CR>',
        switch_to = '<CR>',
        },

    -- you might need to adjust the highlighting, see JABS docs for default values
}

With that config <S-CR> "forces" to open a file a second time instead of switching to it.

@luiz00martins
Copy link
Author

@jeff-dh Yep, that's exactly what I wanted! Thanks a lot man!

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

No branches or pull requests

2 participants