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",
	},
	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)
			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,
				prompt_prefix = " >",
				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 = {},

				mappings = {
					i = {
						["<C-k>"] = actions.move_selection_previous, -- move to prev result
						["<C-j>"] = actions.move_selection_next, -- move to next result
						["<C-q>"] = actions.send_selected_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,
						},
					},
				},
			},
		})

		telescope.load_extension("fzf")
		telescope.load_extension("undo")

		local git_branches = 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

		local find_files = function()
			local ran, errorMessage = pcall(function()
				builtin.git_files({ show_untracked = true })
			end)
			if not ran then
				builtin.find_files()
			end
		end

		-- set keymaps
		local keymap = vim.keymap -- for conciseness

		keymap.set("n", "<C-g>", builtin.live_grep, { desc = "Live grep over project files." })
		keymap.set("n", "<C-p>", find_files, { desc = "Fuzzy find files in cwd" })

		keymap.set("n", "<leader>fb", builtin.buffers, { desc = "Fuzzy find open buffers" })
		keymap.set("n", "<leader>fo", builtin.oldfiles, { desc = "Fuzzy find recently opened files" })

		keymap.set("n", "<leader>m", builtin.marks, { desc = "Fuzzy find marks" })
		keymap.set("n", "<leader>ch", builtin.command_history, { desc = "Fuzzy find recent commands" })

		keymap.set("n", "<leader>gb", git_branches, { desc = "Fuzzy find git branches" })

		keymap.set("n", "<leader>df", function()
			builtin.find_files({
				prompt_title = "< VimRC >",
				cwd = vim.fn.expand("~/.config/nvim"),
				hidden = true,
			})
		end, { desc = "Find neovim config files" })

        keymap.set("n", "<leader>vh", builtin.help_tags, { desc = "Fuzzy find help tags" })

        keymap.set("n", "<leader>gf", function ()
            builtin.grep_string({
                search = vim.fn.expand("<cword>"),
            })
        end, { desc = "Find neovim config files with FZF" })

        keymap.set("n", "<leader>gF", function ()
            builtin.grep_string({
                search = vim.fn.expand("<cWORD>"),
            })
        end, { desc = "Find neovim config files with FZF" })

        keymap.set("n", "<leader>gD", function ()
            builtin.find_files({
                search_file = vim.fn.expand("<cword>"),
            })
        end, { desc = "Find neovim config files with FZF" })

		vim.keymap.set("n", "<leader>u", "<cmd>Telescope undo<cr>")
	end,
}
