This repository has been archived on 2024-05-02. You can view files and clone it, but cannot push or open issues or pull requests.
neovim-flake/neovim-ide/plugin/telescope.lua

104 lines
3.7 KiB
Lua

local telescope = require("telescope")
local actions = require("telescope.actions")
local builtin = require("telescope.builtin")
local telescope_config = require("telescope.config")
-- Clone the default Telescope configuration
local vimgrep_arguments = { unpack(telescope_config.values.vimgrep_arguments) }
-- I want to search in hidden/dot files.
table.insert(vimgrep_arguments, "--hidden")
-- I don't want to search in the `.git` directory.
table.insert(vimgrep_arguments, "--glob")
table.insert(vimgrep_arguments, "!**/.git/*")
local is_inside_work_tree = {}
local project_files = function()
local opts = {} -- define here if you want to define something
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(opts)
else
builtin.find_files(opts)
end
end
telescope.setup {
defaults = {
prompt_prefix = "",
selection_caret = " ",
entry_prefix = " ",
initial_mode = "insert",
selection_strategy = "reset",
sorting_strategy = "ascending",
layout_strategy = "horizontal",
vimgrep_arguments = vimgrep_arguments,
layout_config = {
horizontal = {
prompt_position = "top",
preview_width = 0.55,
results_width = 0.8,
},
vertical = {
mirror = true,
},
width = 0.87,
height = 0.80,
preview_cutoff = 120,
},
file_ignore_patterns = { "node_modules", "vendor" },
path_display = { "truncate" },
winblend = 3,
border = {},
borderchars = { " ", " ", " ", " ", " ", " ", " ", " " },
color_devicons = true,
extensions = {
fzf = {
fuzzy = true, -- false will only do exact matching
override_generic_sorter = true, -- override the generic sorter
override_file_sorter = true, -- override the file sorter
case_mode = "smart_case", -- or "ignore_case" or "respect_case"
},
["ui-select"] = {
require("telescope.themes").get_dropdown({})
}
},
mappings = {
i = {
["<esc>"] = actions.close
},
},
pickers = {
find_files = {
-- `hidden = true` will still show the inside of `.git/` as it's not `.gitignore`d.
find_command = { "rg", "--files", "--hidden", "--glob", "!**/.git/*" },
},
},
},
}
-- Enable telescope fzf native, if installed
telescope.load_extension("fzf")
telescope.load_extension("noice")
telescope.load_extension("dap")
telescope.load_extension("ui-select")
--
-- See `:help telescope.builtin`
vim.keymap.set("n", "<leader>fo", builtin.oldfiles, { desc = "Find recently opened files" })
vim.keymap.set("n", "<leader>fb", builtin.buffers, { desc = "] Find existing buffers" })
vim.keymap.set("n", "<leader>gf", builtin.git_files, { desc = "Search Git Files" })
vim.keymap.set("n", "<leader>ff", project_files, { desc = "Search Project Files" })
vim.keymap.set("n", "<leader>fF", builtin.find_files, { desc = "Search Files" })
vim.keymap.set("n", "<leader>sh", builtin.help_tags, { desc = "Search Help" })
vim.keymap.set("n", "<leader>fG", builtin.grep_string, { desc = "Search current Word" })
vim.keymap.set("n", "<leader>fg", builtin.live_grep, { desc = "Search by Grep" })
vim.keymap.set("n", "<leader>sd", builtin.diagnostics, { desc = "Search Diagnostics" })
vim.keymap.set("n", "<leader>fr", builtin.resume, { desc = "Search Resume" })