telescope.lua (3242B)
1 local vim = vim 2 local sizes = { 3 center_height = math.floor(vim.o.lines * 0.6), 4 center_width = math.floor(vim.o.columns * 0.6), 5 } 6 7 local function pct(value, total) 8 return math.floor(total * value) 9 end 10 11 local picker_layouts = { 12 find_files = { height = 0.4, width = 0.5, anchor = "SW" }, 13 current_buffer_fuzzy_find = { height = 0.4, width = 0.5, anchor = "SW" }, 14 buffers = { height = 0.45, width = 0.5, anchor = "SW" }, 15 } 16 17 local function builtin(name, opts) 18 return function() 19 require("telescope.builtin")[name](opts) 20 end 21 end 22 23 return { 24 "nvim-telescope/telescope.nvim", 25 lazy = false, 26 version = "*", 27 dependencies = { 28 "nvim-lua/plenary.nvim", 29 { "nvim-telescope/telescope-fzf-native.nvim", build = "make" }, 30 "echasnovski/mini.icons", 31 }, 32 opts = { 33 defaults = { 34 vimgrep_arguments = { 35 "rg", 36 "--color=never", 37 "--no-heading", 38 "--with-filename", 39 "--line-number", 40 "--column", 41 "--smart-case", 42 "--hidden", 43 "--glob", 44 "!.git/", 45 }, 46 layout_strategy = "center", 47 layout_config = { 48 height = sizes.center_height, 49 width = sizes.center_width, 50 prompt_position = "top", 51 anchor = "S", 52 }, 53 sorting_strategy = "ascending", 54 previewer = false, 55 border = true, 56 }, 57 pickers = { 58 find_files = { 59 previewer = false, 60 hidden = true, 61 }, 62 current_buffer_fuzzy_find = { previewer = false }, 63 buffers = { previewer = false }, 64 }, 65 }, 66 config = function(_, opts) 67 for picker, layout in pairs(picker_layouts) do 68 opts.pickers[picker] = vim.tbl_extend("force", opts.pickers[picker], { 69 layout_strategy = "vertical", 70 layout_config = { 71 height = pct(layout.height, vim.o.lines), 72 width = pct(layout.width, vim.o.columns), 73 prompt_position = "top", 74 anchor = layout.anchor, 75 }, 76 }) 77 end 78 79 require("telescope").setup(opts) 80 require("telescope").load_extension("fzf") 81 require("telescope").load_extension("session-lens") 82 end, 83 84 keys = { 85 { 86 "<leader><leader>", 87 builtin("find_files"), 88 desc = "Find Files in project directory", 89 }, 90 { 91 "<leader>fg", 92 builtin("live_grep"), 93 desc = "Find by grepping in project directory", 94 }, 95 { 96 "<leader>fc", 97 builtin("find_files", { cwd = vim.fn.stdpath("config") }), 98 desc = "Find in neovim configuration", 99 }, 100 { 101 "<leader>fh", 102 builtin("help_tags"), 103 desc = "[F]ind [H]elp", 104 }, 105 { 106 "<leader>fk", 107 builtin("keymaps"), 108 desc = "[F]ind [K]eymaps", 109 }, 110 { 111 "<leader>fB", 112 builtin("builtin"), 113 desc = "[F]ind [B]uiltin Telescope", 114 }, 115 { 116 "<leader>fw", 117 builtin("grep_string", { search = vim.fn.expand("<cword>") }), 118 desc = "[F]ind current [W]ord", 119 }, 120 { 121 "<leader>fW", 122 builtin("grep_string", { search = vim.fn.expand("<cWORD>") }), 123 desc = "[F]ind current [W]ORD", 124 }, 125 { 126 "<leader>fd", 127 builtin("diagnostics", { bufnr = 0 }), 128 desc = "[F]ind [D]iagnostics", 129 }, 130 { 131 "<leader>fr", 132 builtin("resume"), 133 desc = "[F]ind [R]esume", 134 }, 135 { 136 "<leader>fo", 137 builtin("oldfiles"), 138 desc = "[F]ind [O]ld Files", 139 }, 140 { 141 "<leader>b", 142 builtin("buffers"), 143 desc = "[,] Find existing buffers", 144 }, 145 { 146 "<leader>/", 147 builtin("current_buffer_fuzzy_find"), 148 desc = "[/] Live grep the current buffer", 149 }, 150 }, 151 }