diff --git a/nvim/lua/opdavies/telescope/multigrep.lua b/nvim/lua/opdavies/telescope/multigrep.lua new file mode 100644 index 0000000..d4418c5 --- /dev/null +++ b/nvim/lua/opdavies/telescope/multigrep.lua @@ -0,0 +1,57 @@ +local conf = require("telescope.config").values +local finders = require "telescope.finders" +local make_entry = require "telescope.make_entry" +local pickers = require "telescope.pickers" + +local M = {} + +local live_multigrep = function(opts) + opts = opts or {} + opts.cwd = opts.cwd or vim.uv.cwd() + + local finder = finders.new_async_job { + command_generator = function(prompt) + if not prompt or prompt == "" then + return nil + end + + local pieces = vim.split(prompt, " ") + local args = { "rg" } + + if pieces[1] then + table.insert(args, "-e") + table.insert(args, pieces[1]) + end + + if pieces[2] then + table.insert(args, "-g") + table.insert(args, pieces[2]) + end + + ---@diagnostic disable-next-line: deprecated + return vim.tbl_flatten { + args, + { "--color=never", "--no-heading", "--with-filename", "--line-number", "--column", "--smart-case" }, + } + end, + + cwd = opts.cwd, + entry_maker = make_entry.gen_from_vimgrep(opts), + } + + pickers + .new(opts, { + debounce = 100, + finder = finder, + previewer = conf.grep_previewer(opts), + prompt_title = "Multi Grep", + sorter = require("telescope.sorters").empty(), + }) + :find() +end + +M.setup = function() + vim.keymap.set("n", "fg", live_multigrep) +end + +return M diff --git a/nvim/plugin/telescope.lua b/nvim/plugin/telescope.lua index 79fafd6..cc769d9 100644 --- a/nvim/plugin/telescope.lua +++ b/nvim/plugin/telescope.lua @@ -50,7 +50,6 @@ end vim.keymap.set("n", "/", builtin.current_buffer_fuzzy_find) vim.keymap.set("n", "fb", builtin.buffers) vim.keymap.set("n", "fd", builtin.find_files) -vim.keymap.set("n", "fg", builtin.live_grep) vim.keymap.set("n", "fh", builtin.help_tags) vim.keymap.set("n", "fi", M.search_all_files) vim.keymap.set("n", "fk", builtin.keymaps) @@ -65,3 +64,5 @@ vim.keymap.set("n", "dgb", M.grep_bluecheese) vim.keymap.set("n", "dgd", M.grep_drupalorg_theme) vim.keymap.set({ "n", "v" }, "gw", builtin.grep_string) + +require("opdavies.telescope.multigrep").setup {}