return { -- Fuzzy Finder (files, LSP, etc.) 'nvim-telescope/telescope.nvim', cmd = 'Telescope', version = '*', keys = { { 'ff', 'Telescope find_files', desc = 'Find Files' }, { 'fg', 'Telescope live_grep', desc = 'Live Grep' }, { 'fb', 'Telescope buffers', desc = 'Buffers' }, { 'fh', 'Telescope help_tags', desc = 'Help Tags' }, { 'fr', 'Telescope oldfiles', desc = 'Recent Files' }, }, dependencies = { 'nvim-lua/plenary.nvim', { 'nvim-telescope/telescope-fzf-native.nvim', build = 'make' }, 'nvim-tree/nvim-web-devicons', }, config = function() local telescope = require('telescope') -- Configure Telescope telescope.setup({ defaults = { -- prompt_prefix = '🔍 ', sorting_strategy = 'descending', layout_strategy = 'flex', mappings = { i = { [''] = false, -- Disable Ctrl+u clearing input [''] = false, -- Disable Ctrl+d clearing input }, }, -- Attach the global mapping for centering the cursor on selection attach_mappings = function(prompt_bufnr, _) local actions = require('telescope.actions') -- When selecting a result, center it in the middle of the screen actions.select_default:replace(function() local line = actions.state.get_selected_entry().lnum vim.api.nvim_win_set_cursor(0, { line, 0 }) vim.cmd('normal! zz') -- This centers the line in the middle of the screen actions.close(prompt_bufnr) -- Close the Telescope window end) return true end, }, extensions = { fzf = {}, }, }) -- Load the fzf extension for Telescope telescope.load_extension('fzf') -- Function to find git root directory local function find_git_root() local current_file = vim.api.nvim_buf_get_name(0) local current_dir = current_file ~= '' and vim.fn.fnamemodify(current_file, ':h') or vim.fn.getcwd() local git_root = vim.fn.systemlist('git -C ' .. vim.fn.escape(current_dir, ' ') .. ' rev-parse --show-toplevel')[1] if vim.v.shell_error ~= 0 then print('Not a git repository, searching in current directory.') return vim.fn.getcwd() end return git_root end -- Function for live_grep within the Git root local function live_grep_git_root() local git_root = find_git_root() if git_root then require('telescope.builtin').live_grep({ search_dirs = { git_root } }) end end -- Command to trigger live_grep_git_root vim.api.nvim_create_user_command('LiveGrepGitRoot', live_grep_git_root, { desc = 'Live grep in Git root' }) end, }