diff --git a/README.md b/README.md index fae7b8b..c333988 100644 --- a/README.md +++ b/README.md @@ -45,6 +45,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 | \b | Search though open buffers | +| IvyLines | | Search the lines in the current buffer | ### Actions diff --git a/lua/ivy/utils.lua b/lua/ivy/utils.lua index c087167..6fa8f67 100644 --- a/lua/ivy/utils.lua +++ b/lua/ivy/utils.lua @@ -54,4 +54,11 @@ utils.file_action = function() end end +utils.line_action = function() + return function(item) + local line = item:match "^%s+(%d+):" + vim.cmd(line) + end +end + return utils diff --git a/plugin/ivy.lua b/plugin/ivy.lua index 92f22f6..2744c71 100644 --- a/plugin/ivy.lua +++ b/plugin/ivy.lua @@ -42,6 +42,28 @@ vim.api.nvim_create_user_command("IvyBuffers", function() end, utils.file_action()) end, { bang = true, desc = "List all of the current open buffers" }) +vim.api.nvim_create_user_command("IvyLines", function() + vim.ivy.run("Lines", function(input) + local list = {} + + local lines = vim.api.nvim_buf_get_lines(vim.ivy.origin(), 0, -1, false) + for index = 1, #lines do + local line = lines[index] + local score = libivy.ivy_match(input, line) + if score > -200 then + local prefix = string.rep(" ", 4 - #tostring(index)) .. index .. ": " + table.insert(list, { score, prefix .. line }) + end + end + + table.sort(list, function(a, b) + return a[1] < b[1] + end) + + return list + end, utils.line_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 })