feat: implement IvyLines to search the lines in the current buffer
This commit is contained in:
parent
7577706545
commit
9b3d186701
3 changed files with 30 additions and 0 deletions
|
|
@ -45,6 +45,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 |
|
||||
| IvyAg | \<leader\>/ | Find content in files using the silver searcher |
|
||||
| IvyBuffers | \<leader\>b | Search though open buffers |
|
||||
| IvyLines | | Search the lines in the current buffer |
|
||||
|
||||
### Actions
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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", "<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>/", "<cmd>IvyAg<CR>", { nowait = true, silent = true })
|
||||
|
|
|
|||
Loading…
Reference in a new issue