diff --git a/nvim/init.lua b/nvim/init.lua index 3781339..14fd7d6 100644 --- a/nvim/init.lua +++ b/nvim/init.lua @@ -147,6 +147,22 @@ vim.keymap.set('n', '', '', { desc = 'Move focus to the right win vim.keymap.set('n', '', '', { desc = 'Move focus to the lower window' }) vim.keymap.set('n', '', '', { desc = 'Move focus to the upper window' }) +-- [[ Utility functions ]] + +-- Retreive selected text from the editor. +function vim.getVisualSelection() + vim.cmd 'noau normal! "vy"' + local text = vim.fn.getreg 'v' + vim.fn.setreg('v', {}) + + text = string.gsub(text, '\n', '') + if #text > 0 then + return text + else + return '' + end +end + -- [[ Basic Autocommands ]] -- See `:help lua-guide-autocommands` @@ -316,6 +332,13 @@ require('lazy').setup({ } end, { desc = '[S]earch Recent Files in CWD' }) + vim.keymap.set('v', 'g', function() + builtin.grep_string { + search = vim.getVisualSelection(), + prompt_title = 'Grep all files', + } + end, { desc = '[G]rep everywhere' }) + -- Slightly advanced example of overriding default behavior and theme vim.keymap.set('n', '/', function() -- You can pass additional configuration to Telescope to change the theme, layout, etc.