JABS.nvim icon indicating copy to clipboard operation
JABS.nvim copied to clipboard

[Feature Request] Go to currently opened buffer

Open luiz00martins opened this issue 2 years ago • 4 comments

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 avatar Dec 07 '22 21:12 luiz00martins

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.

luiz00martins avatar Dec 07 '22 21:12 luiz00martins

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 avatar Dec 08 '22 03:12 jeff-dh

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.

jeff-dh avatar Dec 08 '22 11:12 jeff-dh

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

luiz00martins avatar Jan 07 '23 14:01 luiz00martins