1
0
Fork 0
numbers/nvim/lua/plugins/telescope.lua

144 lines
3.6 KiB
Lua

local actions = require("telescope.actions")
local previewers = require("telescope.previewers")
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 = {
prompt_title = " ",
results_title = " ",
preview_title = " ",
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" },
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,
},
n = {
["<C-q>"] = actions.smart_send_to_qflist + actions.open_qflist,
},
},
},
})
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.builtin").find_files({cwd = "%:h", hidden=true})<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)