diff --git a/README.md b/README.md index 1b92924..11ec7df 100644 --- a/README.md +++ b/README.md @@ -44,7 +44,7 @@ A command can be run that will launch the completion UI | ---------- | ----------- | ------------------------------------------------------ | | IvyFd | \p | Find files in your project with the fd cli file finder | | IvyAg | \/ | Find content in files using the silver searcher | -| IvyBuffers | | Search though open buffers | +| IvyBuffers | \b | Search though open buffers | ### Actions diff --git a/plugin/ivy.lua b/plugin/ivy.lua index 2032c54..b2bd595 100644 --- a/plugin/ivy.lua +++ b/plugin/ivy.lua @@ -22,15 +22,26 @@ vim.api.nvim_create_user_command("IvyBuffers", function() local buffers = vim.api.nvim_list_bufs() for index = 1, #buffers do local buffer = buffers[index] - local buffer_name = vim.api.nvim_buf_get_name(buffer) + -- Get the relative path from the current working directory. We need to + -- substring +2 to remove the `/` from the start of the path to give us a + -- true relative path + local buffer_name = vim.api.nvim_buf_get_name(buffer):sub(#vim.fn.getcwd() + 2, -1) if vim.api.nvim_buf_is_loaded(buffer) and #buffer_name > 0 then - table.insert(list, buffer_name) + local score = libivy.ivy_match(input, buffer_name) + if score > -200 or #input == 0 then + table.insert(list, { score, buffer_name }) + end end end + table.sort(list, function(a, b) + return a[1] < b[1] + end) + return list end, utils.file_action()) end, { bang = true, desc = "List all of the current open buffers" }) +vim.api.nvim_set_keymap("n", "b", "IvyBuffers", { nowait = true, silent = true }) vim.api.nvim_set_keymap("n", "p", "IvyFd", { nowait = true, silent = true }) vim.api.nvim_set_keymap("n", "/", "IvyAg", { nowait = true, silent = true })