nvim/lua/config/utils.lua
Jeremie Fraeys 02e26b00b7
Some checks are pending
Check Lua Formatting in MyRepo / Stylua Check (push) Waiting to run
chore(nvim): reinitialize with working config
2026-02-07 21:06:45 -05:00

23 lines
678 B
Lua
Executable file

-- Function to get the current visual selection
local function get_visual_selection()
vim.cmd('noau normal! "vy"')
local text = vim.fn.getreg('v')
-- optional: clear register v
-- vim.fn.setreg('v', '')
text = text:gsub('\n$', '') -- remove trailing newline
return text
end
-- Function to get the current search query
local function get_search_query()
local word_under_cursor = vim.fn.expand('<cword>')
local visual_selection = get_visual_selection() -- call local function directly
return visual_selection ~= '' and visual_selection or word_under_cursor
end
return {
get_visual_selection = get_visual_selection,
get_search_query = get_search_query,
}