feat: add sorting and filtering of buffers via libivy
This commit is contained in:
parent
3f6149d3e1
commit
b30ecd21fe
2 changed files with 14 additions and 3 deletions
|
|
@ -44,7 +44,7 @@ A command can be run that will launch the completion UI
|
||||||
| ---------- | ----------- | ------------------------------------------------------ |
|
| ---------- | ----------- | ------------------------------------------------------ |
|
||||||
| IvyFd | \<leader\>p | Find files in your project with the fd cli file finder |
|
| IvyFd | \<leader\>p | Find files in your project with the fd cli file finder |
|
||||||
| IvyAg | \<leader\>/ | Find content in files using the silver searcher |
|
| IvyAg | \<leader\>/ | Find content in files using the silver searcher |
|
||||||
| IvyBuffers | | Search though open buffers |
|
| IvyBuffers | \<leader\>b | Search though open buffers |
|
||||||
|
|
||||||
### Actions
|
### Actions
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -22,15 +22,26 @@ vim.api.nvim_create_user_command("IvyBuffers", function()
|
||||||
local buffers = vim.api.nvim_list_bufs()
|
local buffers = vim.api.nvim_list_bufs()
|
||||||
for index = 1, #buffers do
|
for index = 1, #buffers do
|
||||||
local buffer = buffers[index]
|
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
|
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
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
table.sort(list, function(a, b)
|
||||||
|
return a[1] < b[1]
|
||||||
|
end)
|
||||||
|
|
||||||
return list
|
return list
|
||||||
end, utils.file_action())
|
end, utils.file_action())
|
||||||
end, { bang = true, desc = "List all of the current open buffers" })
|
end, { bang = true, desc = "List all of the current open buffers" })
|
||||||
|
|
||||||
|
vim.api.nvim_set_keymap("n", "<leader>b", "<cmd>IvyBuffers<CR>", { nowait = true, silent = true })
|
||||||
vim.api.nvim_set_keymap("n", "<leader>p", "<cmd>IvyFd<CR>", { nowait = true, silent = true })
|
vim.api.nvim_set_keymap("n", "<leader>p", "<cmd>IvyFd<CR>", { nowait = true, silent = true })
|
||||||
vim.api.nvim_set_keymap("n", "<leader>/", "<cmd>IvyAg<CR>", { nowait = true, silent = true })
|
vim.api.nvim_set_keymap("n", "<leader>/", "<cmd>IvyAg<CR>", { nowait = true, silent = true })
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue