---Get the current visual selection ---@return string The selected text or empty string if no selection local function get_visual_selection() vim.cmd('noau normal! "vy"') local text = vim.fn.getreg('v') text = text:gsub('\n$', '') -- remove trailing newline return text end ---Get the search query (visual selection or word under cursor) ---@return string The query to search for local function get_search_query() local word_under_cursor = vim.fn.expand('') local visual_selection = get_visual_selection() return visual_selection ~= '' and visual_selection or word_under_cursor end return { get_visual_selection = get_visual_selection, get_search_query = get_search_query, }