You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

181 lines
6.3 KiB

return {
"nvim-telescope/telescope.nvim",
dependencies = {
"nvim-lua/plenary.nvim",
{ "nvim-telescope/telescope-fzf-native.nvim", build = "make" },
"nvim-tree/nvim-web-devicons",
"debugloop/telescope-undo.nvim",
"nvim-telescope/telescope-ui-select.nvim",
},
config = function()
local telescope = require("telescope")
local actions = require("telescope.actions")
local previewers = require("telescope.previewers")
local previewers_utils = require("telescope.previewers.utils")
local sorters = require("telescope.sorters")
local builtin = require("telescope.builtin")
local max_size = 100000
local truncate_large_files = function(filepath, bufnr, opts)
opts = opts or {}
filepath = vim.fn.expand(filepath)
---@diagnostic disable-next-line: undefined-field
vim.loop.fs_stat(filepath, function(_, stat)
if not stat then
return
end
if stat.size > max_size then
local cmd = { "head", "-c", max_size, filepath }
previewers_utils.job_maker(cmd, bufnr, opts)
else
previewers.buffer_previewer_maker(filepath, bufnr, opts)
end
end)
end
telescope.setup({
defaults = {
file_sorter = sorters.get_fzy_sorter,
color_devicons = true,
buffer_previewer_maker = truncate_large_files,
initial_mode = "insert",
selection_strategy = "reset",
sorting_strategy = "ascending",
layout_strategy = "horizontal",
layout_config = {
horizontal = {
prompt_position = "top",
preview_width = 0.55,
results_width = 0.8,
},
vertical = {
mirror = false,
},
width = 0.87,
height = 0.80,
preview_cutoff = 120,
},
path_display = { "truncate" },
winblend = 0,
border = {},
borderchars = nil,
mappings = {
i = {
["<C-n>"] = actions.move_selection_next,
["<C-p>"] = actions.move_selection_previous,
["<C-j>"] = actions.cycle_history_next,
["<C-k>"] = actions.cycle_history_prev,
["<C-q>"] = actions.smart_send_to_qflist + actions.open_qflist,
},
},
},
extensions = {
undo = {
side_by_side = true,
mappings = {
i = {
["<CR>"] = require("telescope-undo.actions").restore,
},
n = {
["<CR>"] = require("telescope-undo.actions").restore,
["y"] = require("telescope-undo.actions").yank_additions,
["Y"] = require("telescope-undo.actions").yank_deletions,
["u"] = require("telescope-undo.actions").restore,
},
},
},
["ui-select"] = {
require("telescope.themes").get_dropdown({}),
},
},
})
telescope.load_extension("fzf")
telescope.load_extension("undo")
telescope.load_extension("ui-select")
-- We cache the results of "git rev-parse"
-- Process creation is expensive in Windows, so this reduces latency
local is_inside_work_tree = {}
local project_files = function()
local cwd = vim.fn.getcwd()
if is_inside_work_tree[cwd] == nil then
vim.fn.system("git rev-parse --is-inside-work-tree")
is_inside_work_tree[cwd] = vim.v.shell_error == 0
end
if is_inside_work_tree[cwd] then
builtin.git_files({ show_untracked = true, hidden = true })
else
builtin.find_files({})
end
end
-- set keymaps
local keymap = vim.keymap
keymap.set("n", "<C-g>", function()
builtin.live_grep({ hidden = true })
end, {})
keymap.set("n", "<leader>ff", function()
builtin.live_grep({ hidden = true })
end, {})
keymap.set("n", "<C-p>", project_files, {})
keymap.set("n", "<leader>p", project_files, {})
keymap.set("n", "<leader>fr", builtin.resume, {})
keymap.set("n", "<leader>fb", builtin.buffers, {})
keymap.set("n", "<leader>fo", builtin.oldfiles, {})
keymap.set("n", "<leader>m", builtin.marks, {})
keymap.set("n", "<leader>cc", builtin.commands, {})
keymap.set("n", "<leader>ch", builtin.command_history, {})
keymap.set("n", "<leader>gb", function()
builtin.git_branches({
attach_mappings = function(_, map)
map("i", "<c-d>", actions.git_delete_branch)
map("n", "<c-d>", actions.git_delete_branch)
return true
end,
})
end, {})
keymap.set("n", "<leader>gc", builtin.git_commits, {})
keymap.set("n", "<leader>vh", builtin.help_tags, {})
keymap.set("n", "<leader>ds", builtin.lsp_document_symbols, {})
keymap.set("n", "<leader>ws", builtin.lsp_workspace_symbols, {})
keymap.set("n", "<leader>dws", builtin.lsp_dynamic_workspace_symbols, {})
keymap.set("n", "<leader>gf", function()
builtin.grep_string({
search = vim.fn.expand("<cword>"),
})
end)
keymap.set("n", "<leader>gF", function()
builtin.grep_string({
search = vim.fn.expand("<cWORD>"),
})
end)
keymap.set("n", "<leader>gD", function()
builtin.find_files({
search_file = vim.fn.expand("<cword>"),
})
end)
vim.keymap.set("n", "<leader>u", "<cmd>Telescope undo<cr>")
end,
}