return { 'nvim-telescope/telescope.nvim', cmd = 'Telescope', keys = { { 'ff', 'Telescope find_files', desc = 'Find Files' }, { 'fg', 'Telescope live_grep', desc = 'Live Grep' }, { 'fG', 'LiveGrepGitRoot', desc = 'Live Grep Git Root' }, { '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', optional = true }, }, config = function() local telescope = require('telescope') local actions = require('telescope.actions') telescope.setup({ defaults = { sorting_strategy = 'descending', layout_strategy = 'flex', mappings = { i = { [''] = false, [''] = false, [''] = function(prompt_bufnr) -- close first, then center -- this is the correct order actions.select_default(prompt_bufnr) vim.cmd('normal! zz') end, }, }, }, extensions = { fzf = {} }, }) telescope.load_extension('fzf') 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 return vim.fn.getcwd() end return git_root end vim.api.nvim_create_user_command('LiveGrepGitRoot', function() require('telescope.builtin').live_grep({ search_dirs = { find_git_root() } }) end, { desc = 'Live grep in Git root' }) end, }