You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

106 lines
2.9 KiB

  1. local previewers = require('telescope.previewers')
  2. local previewers_utils = require('telescope.previewers.utils')
  3. local builtin = require('telescope.builtin')
  4. local sorters = require('telescope.sorters')
  5. local actions = require('telescope.actions')
  6. local max_size = 100000
  7. local truncate_large_files = function(filepath, bufnr, opts)
  8. opts = opts or {}
  9. filepath = vim.fn.expand(filepath)
  10. vim.loop.fs_stat(filepath, function(_, stat)
  11. if not stat then return end
  12. if stat.size > max_size then
  13. local cmd = {"head", "-c", max_size, filepath}
  14. previewers_utils.job_maker(cmd, bufnr, opts)
  15. else
  16. previewers.buffer_previewer_maker(filepath, bufnr, opts)
  17. end
  18. end)
  19. end
  20. require('telescope').setup({
  21. defaults = {
  22. file_sorter = sorters.get_fzy_sorter,
  23. prompt_prefix = ' >',
  24. color_devicons = true,
  25. buffer_previewer_maker = truncate_large_files,
  26. initial_mode = "insert",
  27. selection_strategy = "reset",
  28. sorting_strategy = "ascending",
  29. layout_strategy = "horizontal",
  30. layout_config = {
  31. horizontal = {
  32. prompt_position = "top",
  33. preview_width = 0.55,
  34. results_width = 0.8,
  35. },
  36. vertical = {
  37. mirror = false,
  38. },
  39. width = 0.87,
  40. height = 0.80,
  41. preview_cutoff = 120,
  42. },
  43. path_display = { "truncate" },
  44. winblend = 0,
  45. border = {},
  46. borderchars = { "", "", "", "", "", "", "", "" },
  47. mappings = {
  48. i = {
  49. ['<C-x>'] = false,
  50. ['<C-q>'] = actions.send_to_qflist,
  51. },
  52. },
  53. },
  54. })
  55. function git_branches ()
  56. builtin.git_branches({
  57. attach_mappings = function(_, map)
  58. map("i", "<c-d>", actions.git_delete_branch)
  59. map("n", "<c-d>", actions.git_delete_branch)
  60. return true
  61. end,
  62. })
  63. end
  64. function files ()
  65. local ran, errorMessage = pcall(function()
  66. builtin.git_files({ show_untracked = true })
  67. end)
  68. if not ran then
  69. builtin.find_files()
  70. end
  71. end
  72. local options = { noremap = true }
  73. vim.keymap.set('n', '<C-g>', builtin.live_grep, options)
  74. vim.keymap.set('n', '<C-p>', files, options)
  75. vim.keymap.set('n', '<leader>df', function()
  76. builtin.find_files({
  77. prompt_title = "< VimRC >",
  78. cwd = vim.fn.expand('~/.config/nvim'),
  79. hidden = true,
  80. })
  81. end, options)
  82. vim.keymap.set('n', '<leader>fb', builtin.buffers, options)
  83. vim.keymap.set('n', '<leader>fo', builtin.oldfiles, options)
  84. vim.keymap.set('n', '<leader>gr', builtin.lsp_references, options)
  85. vim.keymap.set("n", '<leader>gi', builtin.lsp_implementations, options)
  86. vim.keymap.set("n", '<leader>gT', builtin.lsp_type_definitions, options)
  87. vim.keymap.set('n', '<leader>m', builtin.marks, options)
  88. vim.keymap.set('n', '<leader>ch', builtin.command_history, options)
  89. vim.keymap.set('n', '<leader>gb', git_branches, options)
  90. vim.keymap.set('n', '<leader>gs', builtin.git_status, options)