nvim/lua/config/utils.lua
Jeremie Fraeys 4742e3a251
Some checks are pending
Check Lua Formatting in MyRepo / Stylua Check (push) Waiting to run
refactor: reorganize config and simplify README
2026-02-08 14:48:48 -05:00

22 lines
703 B
Lua
Executable file

---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('<cword>')
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,
}