nvim/lua/plugins/telescope.lua

125 lines
3.7 KiB
Lua

local function normalize_path(path)
return path:gsub("\\", "/")
end
local function normalize_cwd()
return normalize_path(vim.loop.cwd()) .. "/"
end
local function is_subdirectory(cwd, path)
return string.lower(path:sub(1, #cwd)) == string.lower(cwd)
end
local function split_filepath(path)
local normalized_path = normalize_path(path)
local normalized_cwd = normalize_cwd()
local filename = normalized_path:match("[^/]+$")
if is_subdirectory(normalized_cwd, normalized_path) then
local stripped_path = normalized_path:sub(#normalized_cwd + 1, -(#filename + 1))
return stripped_path, filename
else
local stripped_path = normalized_path:sub(1, -(#filename + 1))
return stripped_path, filename
end
end
local function path_display(_, path)
local stripped_path, filename = split_filepath(path)
if filename == stripped_path or stripped_path == "" then
return filename
end
return string.format("%-25s ~ %s", filename, stripped_path)
end
return {
{
"nvim-telescope/telescope.nvim",
branch = "0.1.x",
dependencies = {
{
"nvim-telescope/telescope-fzf-native.nvim",
build = "make",
lazy = true,
},
"nvim-lua/plenary.nvim",
},
opts = {},
config = function()
require("telescope").setup({
defaults = {
path_display = path_display,
preview = false,
entry_prefix = " ",
initial_mode = "insert",
selection_strategy = "reset",
-- path_display = { "smart" },
vimgrep_arguments = {
"rg",
"--color=never",
"--no-heading",
"--with-filename",
"--line-number",
"--column",
"--smart-case",
"--hidden",
"--glob=!.git/",
},
},
pickers = {
find_files = { theme = "dropdown" },
git_files = { theme = "dropdown" },
live_grep = { preview = true, theme = "dropdown" },
buffers = { theme = "dropdown" },
grep_string = { preview = true, theme = "dropdown" },
help_tags = { theme = "dropdown" },
},
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"
},
},
})
local builtin = require("telescope.builtin")
vim.keymap.set("n", "<leader>pp", "<cmd>:Telescope projects theme=dropdown<CR>", {})
vim.keymap.set("n", "<leader>ff", builtin.find_files, {})
vim.keymap.set("n", "<leader>pf", builtin.git_files, {})
vim.keymap.set("n", "<leader>bb", builtin.buffers, {})
vim.keymap.set("n", "<leader>bi", "<cmd>:Telescope buffers theme=ivy<CR>", {})
vim.keymap.set("n", "<leader>pws", function()
local word = vim.fn.expand("<cword>")
builtin.grep_string({ search = word })
end)
vim.keymap.set("n", "<leader>pWs", function()
local word = vim.fn.expand("<cWORD>")
builtin.grep_string({ search = word })
end)
vim.keymap.set("n", "<leader>ps", function()
builtin.grep_string({ search = vim.fn.input("Grep > ") })
end)
-- vim.keymap.set("n", "<leader>pg", builtin.live_grep, {})
vim.keymap.set("n", "<leader>vh", builtin.help_tags, {})
end,
},
-- {
-- "ahmedkhalf/project.nvim",
-- config = function()
-- require("project_nvim").setup({
-- manual_mode = false,
-- detection_methods = { "lsp", "pattern" },
-- patterns = { ".git", "_darcs", ".hg", ".bzr", ".svn", "Makefile", "package.json" },
-- ignore_lsp = {},
-- exclude_dirs = {},
-- show_hidden = false,
-- silent_chdir = true,
-- scope_chdir = "global",
-- datapath = vim.fn.stdpath("data"),
-- })
-- require("telescope").load_extension("projects")
-- end,
-- },
}