187 lines
4.8 KiB
Lua
187 lines
4.8 KiB
Lua
local actions = require("telescope.actions")
|
|
local previewers = require("telescope.previewers")
|
|
local builtin = require("telescope.builtin")
|
|
local Job = require("plenary.job")
|
|
|
|
local new_maker = function(filepath, bufnr, opts)
|
|
filepath = vim.fn.expand(filepath)
|
|
Job
|
|
:new({
|
|
command = "file",
|
|
args = { "--mime-type", "-b", filepath },
|
|
on_exit = function(j)
|
|
local mime_type = vim.split(j:result()[1], "/")[1]
|
|
if mime_type == "text" then
|
|
previewers.buffer_previewer_maker(filepath, bufnr, opts)
|
|
else
|
|
vim.schedule(function()
|
|
vim.api.nvim_buf_set_lines(bufnr, 0, -1, false, { "BINARY" })
|
|
end)
|
|
end
|
|
end,
|
|
})
|
|
:sync()
|
|
end
|
|
|
|
require("telescope").setup({
|
|
defaults = {
|
|
vimgrep_arguments = {
|
|
"rg",
|
|
"--color=never",
|
|
"--no-heading",
|
|
"--with-filename",
|
|
"--line-number",
|
|
"--column",
|
|
"--smart-case",
|
|
"--trim",
|
|
},
|
|
sorting_strategy = "ascending",
|
|
layout_config = {
|
|
width = 0.75,
|
|
prompt_position = "top",
|
|
preview_cutoff = 120,
|
|
},
|
|
pickers = {
|
|
buffers = {
|
|
mappings = {
|
|
n = {
|
|
["d"] = actions.delete_buffer,
|
|
},
|
|
},
|
|
sort_mru = true,
|
|
preview_title = false,
|
|
},
|
|
find_files = {
|
|
find_command = { "fd", "-t f", "-c always", "-H", "--strip-cwd-prefix" },
|
|
hidden = true,
|
|
},
|
|
file_browser = {
|
|
hidden = true,
|
|
},
|
|
lsp_references = {
|
|
initial_mode = "normal",
|
|
sorting_strategy = "ascending",
|
|
layout_strategy = "cursor",
|
|
preview_title = false,
|
|
results_title = false,
|
|
prompt_title = "References",
|
|
layout_config = {
|
|
width = 0.4,
|
|
height = 0.4,
|
|
},
|
|
},
|
|
lsp_code_actions = {
|
|
initial_mode = "normal",
|
|
sorting_strategy = "ascending",
|
|
layout_strategy = "cursor",
|
|
preview = false,
|
|
prompt_title = "Code Actions",
|
|
results_title = "",
|
|
layout_config = {
|
|
width = 0.2,
|
|
height = 0.3,
|
|
},
|
|
},
|
|
lsp_range_code_actions = {
|
|
initial_mode = "normal",
|
|
sorting_strategy = "ascending",
|
|
layout_strategy = "cursor",
|
|
preview = false,
|
|
prompt_title = "Code Actions",
|
|
results_title = "",
|
|
layout_config = {
|
|
width = 0.3,
|
|
height = 0.3,
|
|
},
|
|
},
|
|
lsp_document_diagnostics = {
|
|
initial_mode = "normal",
|
|
sorting_strategy = "ascending",
|
|
layout_strategy = "cursor",
|
|
prompt_title = "Diagnostics",
|
|
results_title = "",
|
|
layout_config = {
|
|
width = 0.5,
|
|
height = 0.5,
|
|
},
|
|
},
|
|
lsp_definitions = {
|
|
layout_strategy = "cursor",
|
|
prompt_title = "Definitions",
|
|
preview_title = false,
|
|
results_title = false,
|
|
layout_config = {
|
|
width = 0.5,
|
|
height = 0.5,
|
|
},
|
|
},
|
|
},
|
|
selection_caret = "→",
|
|
color_devicons = true,
|
|
file_ignore_patterns = { "node_modules", ".git" },
|
|
set_env = { ["COLORTERM"] = "truecolor" },
|
|
buffer_previewer_maker = new_maker,
|
|
mappings = {
|
|
i = {
|
|
["<C-q>"] = actions.smart_send_to_qflist + actions.open_qflist,
|
|
["<C-x>"] = false,
|
|
["<C-o>"] = actions.select_horizontal,
|
|
["<CR>"] = actions.select_default + actions.center,
|
|
["<esc>"] = actions.close,
|
|
["<C-j>"] = actions.move_selection_next,
|
|
["<C-k>"] = actions.move_selection_previous,
|
|
["<TAB>"] = actions.toggle_selection + actions.move_selection_next,
|
|
["<C-s>"] = actions.send_selected_to_qflist,
|
|
},
|
|
n = {
|
|
["<C-q>"] = actions.smart_send_to_qflist + actions.open_qflist,
|
|
},
|
|
},
|
|
},
|
|
})
|
|
|
|
Project_files = function()
|
|
local opts = {}
|
|
local ok = pcall(require("telescope.builtin").git_files, opts)
|
|
if not ok then
|
|
require("telescope.builtin").find_files(opts)
|
|
end
|
|
end
|
|
|
|
local delta = previewers.new_termopen_previewer({
|
|
get_command = function(entry)
|
|
return { "git", "-c", "core.pager=delta", "-c", "delta.side-by-side=false", "diff", entry.value .. "^!" }
|
|
end,
|
|
})
|
|
|
|
Delta_git_commits = function(opts)
|
|
opts = opts or {}
|
|
opts.previewer = {
|
|
delta,
|
|
previewers.git_commit_message.new(opts),
|
|
previewers.git_commit_diff_as_was.new(opts),
|
|
}
|
|
|
|
builtin.git_commits(opts)
|
|
end
|
|
|
|
Delta_git_bcommits = function(opts)
|
|
opts = opts or {}
|
|
opts.previewer = {
|
|
delta,
|
|
previewers.git_commit_message.new(opts),
|
|
previewers.git_commit_diff_as_was.new(opts),
|
|
}
|
|
|
|
builtin.git_bcommits(opts)
|
|
end
|
|
|
|
local default_opts = { noremap = true, silent = true }
|
|
vim.api.nvim_set_keymap("n", "<F1>", "<cmd>Telescope help_tags<CR>", default_opts)
|
|
vim.api.nvim_set_keymap("n", "<F2>", '<cmd>lua require("telescope").Project_files()<CR>', default_opts)
|
|
vim.api.nvim_set_keymap("n", "<F3>", "<cmd>Telescope file_browser hidden=true<CR>", default_opts)
|
|
vim.api.nvim_set_keymap("n", "<F4>", "<cmd>Telescope buffers<CR>", default_opts)
|
|
vim.api.nvim_set_keymap("n", "<M-f>", "<cmd>Telescope live_grep<CR>", default_opts)
|
|
vim.api.nvim_set_keymap("n", "<M-g>", "<cmd>Telescope git_commits<CR>", default_opts)
|
|
vim.api.nvim_set_keymap("n", "<M-S-r>", "<cmd>Telescope resume<CR>", default_opts)
|