VoxelPrismatic / rabbit.nvim

Quickly jump between buffers
56 stars 0 forks source link

Add quick toggle for last rabbit entry #3

Closed stormpat closed 4 months ago

stormpat commented 4 months ago

This plugin is actually what i was building myself! Great work! I have a small nitpick i wanted to address.

I have been using ,, (vim.keymap.set('n', ',,', ':e#<CR>') to switch to the alternate buffer for years. But it has its problems, like it does not consider deleted buffers etc, all these issues seem to be handled by rabbit, so thats a very positive thing.

So basically i want a keymap that automatically jumps to the most recent used buffer (rabbits first entry). This way i can cut down one key press, and avoid going to the rabbit UI first.

I tried with creating a command like rabbit.func.select(N) but it does not work as i expected. I guess the N = 0/1 is not the first entry in the rabbit history listing. However it does work for N > 1.

Im on mac, but not sure if that matters.

VoxelPrismatic commented 4 months ago

Since the final listing is generated whenever Rabbit is opened, you'll have to open the window. Your keybind can be solved like so:

vim.keymap.set("n", ",,", function()
    require("rabbit").Switch("history")    -- Will close current Rabbit window if necessary
    require("rabbit").func.select(1)       -- Selects the first entry shown to the user
end)

I should probably add an option to ignore hidden buffers. I know Oil only deletes in batches, so calling ,, too quickly may cause you to jump to Oil instead of your last buffer.

stormpat commented 4 months ago

Ok that will work. Thank you!