|
|
- local previewers = require('telescope.previewers')
- local previewers_utils = require('telescope.previewers.utils')
- local builtin = require('telescope.builtin')
- local sorters = require('telescope.sorters')
- local actions = require('telescope.actions')
-
- 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
-
- require('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 = {},
- borderchars = { "─", "│", "─", "│", "╭", "╮", "╯", "╰" },
-
- mappings = {
- i = {
- ['<C-x>'] = false,
- ['<C-q>'] = actions.send_to_qflist,
- },
- },
- },
- })
-
- function git_branches ()
- 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
-
- function files ()
- local ran, errorMessage = pcall(function()
- builtin.git_files({ show_untracked = true })
- end)
- if not ran then
- builtin.find_files()
- end
- end
-
- local options = { noremap = true }
-
- vim.keymap.set('n', '<C-g>', builtin.live_grep, options)
-
- vim.keymap.set('n', '<C-p>', files, options)
-
- vim.keymap.set('n', '<leader>df', function()
- builtin.find_files({
- prompt_title = "< VimRC >",
- cwd = vim.fn.expand('~/.config/nvim'),
- hidden = true,
- })
- end, options)
-
- vim.keymap.set('n', '<leader>fb', builtin.buffers, options)
- vim.keymap.set('n', '<leader>fo', builtin.oldfiles, options)
-
- vim.keymap.set('n', '<leader>gr', builtin.lsp_references, options)
- vim.keymap.set("n", '<leader>gi', builtin.lsp_implementations, options)
- vim.keymap.set("n", '<leader>gT', builtin.lsp_type_definitions, options)
-
- vim.keymap.set('n', '<leader>m', builtin.marks, options)
- vim.keymap.set('n', '<leader>ch', builtin.command_history, options)
-
- vim.keymap.set('n', '<leader>gb', git_branches, options)
- vim.keymap.set('n', '<leader>gs', builtin.git_status, options)
|