-- nvim/.config/nvim/lua/telescope.lua
-- Telescope pickers + keymaps. I keep the config small; the extensions I
-- really use are fzf-native (speed) and ui-select (vim.ui.select handoff).
local ok, telescope = pcall(require, "telescope")
if not ok then return end
local actions = require("telescope.actions")
local builtin = require("telescope.builtin")
telescope.setup({
defaults = {
prompt_prefix = " ",
selection_caret = " ",
sorting_strategy = "ascending",
layout_strategy = "flex",
layout_config = {
flex = { flip_columns = 140 },
horizontal = { preview_width = 0.55, width = 0.9 },
vertical = { preview_cutoff = 10 },
},
path_display = { "truncate" },
dynamic_preview_title = true,
file_ignore_patterns = {
"%.git/", "node_modules/", "target/", "build/", "dist/",
"%.png$", "%.jpg$", "%.ico$", "%.pdf$",
},
mappings = {
i = {
["<C-j>"] = actions.move_selection_next,
["<C-k>"] = actions.move_selection_previous,
["<C-s>"] = actions.select_horizontal,
["<C-v>"] = actions.select_vertical,
["<C-q>"] = actions.send_to_qflist + actions.open_qflist,
["<Esc>"] = actions.close,
},
},
},
pickers = {
find_files = {
hidden = true,
follow = true,
find_command = { "fd", "--type", "f", "--strip-cwd-prefix", "--hidden", "--exclude", ".git" },
},
live_grep = {
additional_args = function() return { "--hidden", "--glob", "!.git/*" } end,
},
buffers = {
sort_mru = true,
ignore_current_buffer = true,
mappings = {
i = { ["<C-d>"] = actions.delete_buffer },
},
},
},
extensions = {
fzf = { fuzzy = true, override_generic_sorter = true, override_file_sorter = true, case_mode = "smart_case" },
["ui-select"] = { require("telescope.themes").get_dropdown({}) },
},
})
pcall(telescope.load_extension, "fzf")
pcall(telescope.load_extension, "ui-select")
-- Keymaps. Everything under <leader>f for "find".
local map = vim.keymap.set
map("n", "<leader>ff", builtin.find_files, { desc = "find files" })
map("n", "<leader>fg", builtin.live_grep, { desc = "live grep" })
map("n", "<leader>fb", builtin.buffers, { desc = "buffers" })
map("n", "<leader>fh", builtin.help_tags, { desc = "help tags" })
map("n", "<leader>fr", builtin.resume, { desc = "resume last picker" })
map("n", "<leader>fd", builtin.diagnostics,{ desc = "diagnostics" })
map("n", "<leader>fs", builtin.lsp_document_symbols, { desc = "document symbols" })
map("n", "<leader>fS", builtin.lsp_dynamic_workspace_symbols, { desc = "workspace symbols" })
map("n", "<leader>fo", builtin.oldfiles, { desc = "recent files" })
map("n", "<leader>fk", builtin.keymaps, { desc = "keymaps" })
-- Grep the word under the cursor.
map("n", "<leader>*",
function() builtin.grep_string({ word_match = "-w" }) end,
{ desc = "grep word under cursor" })
-- Find inside the directory of the current buffer. Handy in monorepos.
map("n", "<leader>fl",
function()
builtin.find_files({ cwd = vim.fn.expand("%:p:h") })
end,
{ desc = "find in file dir" })