1 vim.g.lazyvim_picker = "telescope"
9 -- this will return a function that calls telescope.
10 -- cwd will default to lazyvim.util.get_root
11 -- for `files`, git_files or find_files will be chosen depending on .git
12 ---@param builtin string
13 ---@param opts? lazyvim.util.pick.Opts
14 open = function(builtin, opts)
16 opts.follow = opts.follow ~= false
17 if opts.cwd and opts.cwd ~= vim.uv.cwd() then
18 local function open_cwd_dir()
19 local action_state = require("telescope.actions.state")
20 local line = action_state.get_current_line()
23 vim.tbl_deep_extend("force", {}, opts or {}, {
29 ---@diagnostic disable-next-line: inject-field
30 opts.attach_mappings = function(_, map)
31 -- opts.desc is overridden by telescope, until it's changed there is this fix
32 map("i", "<a-c>", open_cwd_dir, { desc = "Open cwd Directory" })
37 require("telescope.builtin")[builtin](opts)
41 if not LazyVim.pick.register(picker) then
46 { "nvim-telescope/telescope.nvim",
48 version = false, -- telescope did only one release, so use HEAD for now
50 { "nvim-telescope/telescope-fzf-native.nvim",
51 build = "cmake -S. -Bbuild -DCMAKE_BUILD_TYPE=Release && cmake --build build --config Release && cmake --install build --prefix build",
52 config = function(plugin)
53 LazyVim.on_load("telescope.nvim", function()
54 local ok, err = pcall(require("telescope").load_extension, "fzf")
56 local lib = plugin.dir .. "/build/libfzf." .. (LazyVim.is_win() and "dll" or "so")
57 if not vim.uv.fs_stat(lib) then
58 LazyVim.warn("`telescope-fzf-native.nvim` not built. Rebuilding...")
59 require("lazy").build({ plugins = { plugin }, show = false }):wait(function()
60 LazyVim.info("Rebuilding `telescope-fzf-native.nvim` done.\nPlease restart Neovim.")
63 LazyVim.error("Failed to load `telescope-fzf-native.nvim`:\n" .. err)
72 { "<leader>,", "<cmd>Telescope buffers show_all_buffers=true<cr>", desc = "Switch Buffer" },
73 { "<leader>/", LazyVim.pick("live_grep"), desc = "Grep (Root Dir)" },
74 { "<leader>:", "<cmd>Telescope command_history<cr>", desc = "Command History" },
75 -- { "<leader><space>", LazyVim.pick("files"), desc = "Find Files (Root Dir)" },
76 { "<leader><space>", false },
80 "<cmd>Telescope buffers sort_mru=true sort_lastused=true ignore_current_buffer=true<cr>",
83 { "<leader>fc", LazyVim.pick.config_files(), desc = "Find Config File" },
84 -- { "<leader>ff", LazyVim.pick("files"), desc = "Find Files (root dir)" },
85 { "<leader>ff", false }, -- fswitch
86 { "<leader>fF", LazyVim.pick("files", { root = false }), desc = "Find Files (cwd)" },
87 { "<leader>fg", "<cmd>Telescope git_files<cr>", desc = "Find Files (git-files)" },
88 { "<leader>fr", "<cmd>Telescope oldfiles<cr>", desc = "Recent" },
89 { "<leader>fR", LazyVim.pick("oldfiles", { cwd = vim.uv.cwd() }), desc = "Recent (cwd)" },
91 -- { "<leader>gc", "<cmd>Telescope git_commits<CR>", desc = "Commits" },
92 -- { "<leader>gs", "<cmd>Telescope git_status<CR>", desc = "Status" },
93 { "<leader>gc", false },
94 { "<leader>gs", false },
96 { '<leader>s"', "<cmd>Telescope registers<cr>", desc = "Registers" },
97 { "<leader>sa", "<cmd>Telescope autocommands<cr>", desc = "Auto Commands" },
98 { "<leader>sb", "<cmd>Telescope current_buffer_fuzzy_find<cr>", desc = "Buffer" },
99 { "<leader>sc", "<cmd>Telescope command_history<cr>", desc = "Command History" },
100 { "<leader>sC", "<cmd>Telescope commands<cr>", desc = "Commands" },
101 { "<leader>sd", "<cmd>Telescope diagnostics bufnr=0<cr>", desc = "Document Diagnostics" },
102 { "<leader>sD", "<cmd>Telescope diagnostics<cr>", desc = "Workspace Diagnostics" },
103 { "<leader>sg", LazyVim.pick("live_grep"), desc = "Grep (Root Dir)" },
104 { "<leader>sG", LazyVim.pick("live_grep", { root = false }), desc = "Grep (cwd)" },
105 { "<leader>sh", "<cmd>Telescope help_tags<cr>", desc = "Help Pages" },
106 { "<leader>sH", "<cmd>Telescope highlights<cr>", desc = "Search Highlight Groups" },
107 { "<leader>sj", "<cmd>Telescope jumplist<cr>", desc = "Jumplist" },
108 { "<leader>sk", "<cmd>Telescope keymaps<cr>", desc = "Key Maps" },
109 { "<leader>sl", "<cmd>Telescope loclist<cr>", desc = "Location List" },
110 { "<leader>sM", "<cmd>Telescope man_pages<cr>", desc = "Man Pages" },
111 { "<leader>sm", "<cmd>Telescope marks<cr>", desc = "Jump to Mark" },
112 { "<leader>so", "<cmd>Telescope vim_options<cr>", desc = "Options" },
113 { "<leader>sR", "<cmd>Telescope resume<cr>", desc = "Resume" },
114 { "<leader>sq", "<cmd>Telescope quickfix<cr>", desc = "Quickfix List" },
115 { "<leader>sw", LazyVim.pick("grep_string", { word_match = "-w" }), desc = "Word (Root Dir)" },
116 { "<leader>sW", LazyVim.pick("grep_string", { root = false, word_match = "-w" }), desc = "Word (cwd)" },
117 { "<leader>sw", LazyVim.pick("grep_string"), mode = "v", desc = "Selection (Root Dir)" },
118 { "<leader>sW", LazyVim.pick("grep_string", { root = false }), mode = "v", desc = "Selection (cwd)" },
119 { "<leader>uC", LazyVim.pick("colorscheme", { enable_preview = true }), desc = "Colorscheme with Preview" },
122 -- LazyVim.pick("lsp_document_symbols", {
136 -- desc = "Goto Symbol",
138 { "<leader>ss", false }, -- use for snippets below
141 LazyVim.pick("lsp_dynamic_workspace_symbols", {
155 desc = "Goto Symbol (Workspace)",
159 local actions = require("telescope.actions")
161 local open_with_trouble = function(...)
162 return require("trouble.sources.telescope").open(...)
164 local find_files_no_ignore = function()
165 local action_state = require("telescope.actions.state")
166 local line = action_state.get_current_line()
167 LazyVim.pick("find_files", { no_ignore = true, default_text = line })()
169 local find_files_with_hidden = function()
170 local action_state = require("telescope.actions.state")
171 local line = action_state.get_current_line()
172 LazyVim.pick("find_files", { hidden = true, default_text = line })()
175 local function find_command()
176 if 1 == vim.fn.executable("rg") then
177 return { "rg", "--files", "--color", "never", "-g", "!.git" }
178 elseif 1 == vim.fn.executable("fd") then
179 return { "fd", "--type", "f", "--color", "never", "-E", ".git" }
180 elseif 1 == vim.fn.executable("fdfind") then
181 return { "fdfind", "--type", "f", "--color", "never", "-E", ".git" }
182 elseif 1 == vim.fn.executable("find") and vim.fn.has("win32") == 0 then
183 return { "find", ".", "-type", "f" }
184 elseif 1 == vim.fn.executable("where") then
185 return { "where", "/r", ".", "*" }
191 prompt_prefix = " ",
192 selection_caret = " ",
193 -- open files in the first window that is an actual file.
194 -- use the current window if no other window is available.
195 get_selection_window = function()
196 local wins = vim.api.nvim_list_wins()
197 table.insert(wins, 1, vim.api.nvim_get_current_win())
198 for _, win in ipairs(wins) do
199 local buf = vim.api.nvim_win_get_buf(win)
200 if vim.bo[buf].buftype == "" then
208 ["<c-t>"] = open_with_trouble,
209 ["<a-t>"] = open_with_trouble,
210 ["<a-i>"] = find_files_no_ignore,
211 ["<a-h>"] = find_files_with_hidden,
212 ["<C-Down>"] = actions.cycle_history_next,
213 ["<C-Up>"] = actions.cycle_history_prev,
214 ["<C-f>"] = actions.preview_scrolling_down,
215 ["<C-b>"] = actions.preview_scrolling_up,
218 ["q"] = actions.close,
224 find_command = find_command,
232 -- Flash Telescope config
234 "nvim-telescope/telescope.nvim",
236 opts = function(_, opts)
237 if not LazyVim.has("flash.nvim") then
240 local function flash(prompt_bufnr)
241 require("flash").jump({
243 label = { after = { 0, 0 } },
248 return vim.bo[vim.api.nvim_win_get_buf(win)].filetype ~= "TelescopeResults"
252 action = function(match)
253 local picker = require("telescope.actions.state").get_current_picker(prompt_bufnr)
254 picker:set_selection(match.pos[1] - 1)
258 opts.defaults = vim.tbl_deep_extend("force", opts.defaults or {}, {
259 mappings = { n = { s = flash }, i = { ["<c-s>"] = flash } },
264 -- better vim.ui with telescope
266 "stevearc/dressing.nvim",
269 return LazyVim.pick.want() == "telescope"
272 ---@diagnostic disable-next-line: duplicate-set-field
273 vim.ui.select = function(...)
274 require("lazy").load({ plugins = { "dressing.nvim" } })
275 return vim.ui.select(...)
277 ---@diagnostic disable-next-line: duplicate-set-field
278 vim.ui.input = function(...)
279 require("lazy").load({ plugins = { "dressing.nvim" } })
280 return vim.ui.input(...)
286 "neovim/nvim-lspconfig",
288 if LazyVim.pick.want() ~= "telescope" then
291 local Keys = require("lazyvim.plugins.lsp.keymaps").get()
293 vim.list_extend(Keys, {
294 { "gd", function() require("telescope.builtin").lsp_definitions({ reuse_win = true }) end, desc = "Goto Definition", has = "definition" },
295 { "gr", "<cmd>Telescope lsp_references<cr>", desc = "References", nowait = true },
296 { "gI", function() require("telescope.builtin").lsp_implementations({ reuse_win = true }) end, desc = "Goto Implementation" },
297 { "gy", function() require("telescope.builtin").lsp_type_definitions({ reuse_win = true }) end, desc = "Goto T[y]pe Definition" },
303 "benfowler/telescope-luasnip.nvim",
308 require("telescope").load_extension("luasnip")
310 keys = { { "<leader>ss", "<cmd>Telescope luasnip<cr>", desc = "Snippets" } },