From 5adec474310b75615b8c76591f4fc56ec43cc933 Mon Sep 17 00:00:00 2001 From: Folke Lemaitre Date: Thu, 18 Jul 2024 17:01:45 +0200 Subject: [PATCH] feat: use selection when in visual mode --- lua/lazyvim/plugins/editor.lua | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/lua/lazyvim/plugins/editor.lua b/lua/lazyvim/plugins/editor.lua index 72b76568..1f96f8a2 100644 --- a/lua/lazyvim/plugins/editor.lua +++ b/lua/lazyvim/plugins/editor.lua @@ -135,13 +135,16 @@ return { { "sr", function() - require("grug-far").grug_far({ - prefills = { - search = vim.fn.expand(""), - filesFilter = "*." .. vim.fn.expand("%:e"), - }, + local is_visual = vim.fn.mode():lower():find("v") + if is_visual then -- needed to make visual selection work + vim.cmd([[normal! v]]) + end + local grug = require("grug-far"); + (is_visual and grug.with_visual_selection or grug.grug_far)({ + prefills = { filesFilter = "*." .. vim.fn.expand("%:e") }, }) end, + mode = { "n", "v" }, desc = "Search and Replace", }, },