j-morano / buffer_manager.nvim

A simple plugin to easily manage Neovim buffers.
MIT License
232 stars 12 forks source link

Feature: Reorganize Buffers #3

Closed DennisTheMenace780 closed 1 year ago

DennisTheMenace780 commented 1 year ago

Currently the Buffer UI does not allow for ordering buffers. It would be great if we could reorder buffers, such as the example below:

Non-Ordered

1. . 
2. important_file_2
3. important_file_3
4. important_file_1

Ordered

1. .
2. important_file_1
3. important_file_2
4. important_file_3

By reordering the buffers we're able to associate the most important files with keystrokes. A more concrete example of this would be if you had several buffers open, and you wanted the last several buffers to always be your file that contains tests.

j-morano commented 1 year ago

Hi! Thanks for the feedback. I found the idea very interesting, and I have been working on it. As it has required some important changes in ui.lua, I have uploaded the version with this feature to the branch reorganize-buffers (see 1d0c1e9). Would you be willing to test it thoroughly before merging the changes to the main branch? If you use packer.nvim, you can change the branch this way:

  use { 'j-morano/buffer_manager.nvim', branch = 'reorganize-buffers' }

I will close the issue once it is confirmed that it really works as it should.

DennisTheMenace780 commented 1 year ago

Yup! Can give it a go today and see if if anything weird pops out.

j-morano commented 1 year ago

The first version had some bugs related to terminal buffers. The latest changes should fix them.

DennisTheMenace780 commented 1 year ago

I've done some playing around with it and I think it works as expected! The UX of moving things around can probably be enhanced at some point, but that's really a small detail.

Right now I can enter new lines in the buffer, cut-paste the buffers in the order that I want and that works as expected! Thanks for your effort.

j-morano commented 1 year ago

You are welcome! Regarding the UX, I personally do not have the need for changing it, but mostly because I use the following remaps:

local map = vim.keymap.set
opts = {noremap = true}
map('v', 'J', ":m '>+1<CR>gv=gv", opts)
map('v', 'K', ":m '<-2<CR>gv=gv", opts)

With this remaps, you can move a line up and down with capital K and J, respectively. It is true that if you do not have some remaps like these, moving buffers is not so straightforward.

Related to this, here goes an useful trick: since the menu is just a buffer, you can define your own remaps using an autocmd for the file type buffer_manager. For example:

autocmd FileType buffer_manager vnoremap J :m '>+1<CR>gv=gv
autocmd FileType buffer_manager vnoremap J :m '<-2<CR>gv=gv

Finally, thanks for the feedback. Although everything seems to be working well, I will try this branch for a while before merging it with main.

DennisTheMenace780 commented 1 year ago

Sounds great to me! I might those keybinds out then because that would immediately solve the UX problem.

j-morano commented 1 year ago

I have just merged reorganize-buffers branch with main. I think it works fine, so I am closing this issue. Feel free to open another issue if something does not work as expected.