telescope.lua 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. local M = {}
  2. function M.config()
  3. -- Define this minimal config so that it's available if telescope is not yet available.
  4. lvim.builtin.telescope = {
  5. ---@usage disable telescope completely [not recommeded]
  6. active = true,
  7. on_config_done = nil,
  8. }
  9. local status_ok, actions = pcall(require, "telescope.actions")
  10. if not status_ok then
  11. return
  12. end
  13. lvim.builtin.telescope = vim.tbl_extend("force", lvim.builtin.telescope, {
  14. defaults = {
  15. prompt_prefix = " ",
  16. selection_caret = " ",
  17. entry_prefix = " ",
  18. initial_mode = "insert",
  19. selection_strategy = "reset",
  20. sorting_strategy = "descending",
  21. layout_strategy = "horizontal",
  22. layout_config = {
  23. width = 0.75,
  24. prompt_position = "bottom",
  25. preview_cutoff = 120,
  26. horizontal = { mirror = false },
  27. vertical = { mirror = false },
  28. },
  29. file_sorter = require("telescope.sorters").get_fzy_sorter,
  30. file_ignore_patterns = {},
  31. generic_sorter = require("telescope.sorters").get_generic_fuzzy_sorter,
  32. path_display = { shorten = 5 },
  33. winblend = 0,
  34. border = {},
  35. borderchars = { "─", "│", "─", "│", "╭", "╮", "╯", "╰" },
  36. color_devicons = true,
  37. use_less = true,
  38. set_env = { ["COLORTERM"] = "truecolor" }, -- default = nil,
  39. file_previewer = require("telescope.previewers").vim_buffer_cat.new,
  40. grep_previewer = require("telescope.previewers").vim_buffer_vimgrep.new,
  41. qflist_previewer = require("telescope.previewers").vim_buffer_qflist.new,
  42. -- Developer configurations: Not meant for general override
  43. -- buffer_previewer_maker = require("telescope.previewers").buffer_previewer_maker,
  44. mappings = {
  45. i = {
  46. ["<C-n>"] = actions.move_selection_next,
  47. ["<C-p>"] = actions.move_selection_previous,
  48. ["<C-c>"] = actions.close,
  49. ["<C-j>"] = actions.cycle_history_next,
  50. ["<C-k>"] = actions.cycle_history_prev,
  51. ["<C-q>"] = actions.smart_send_to_qflist + actions.open_qflist,
  52. ["<CR>"] = actions.select_default + actions.center,
  53. -- To disable a keymap, put [map] = false
  54. -- So, to not map "<C-n>", just put
  55. -- ["<c-t>"] = trouble.open_with_trouble,
  56. -- ["<c-x>"] = false,
  57. -- ["<esc>"] = actions.close,
  58. -- Otherwise, just set the mapping to the function that you want it to be.
  59. -- ["<C-i>"] = actions.select_horizontal,
  60. -- Add up multiple actions
  61. -- You can perform as many actions in a row as you like
  62. -- ["<CR>"] = actions.select_default + actions.center + my_cool_custom_action,
  63. },
  64. n = {
  65. ["<C-n>"] = actions.move_selection_next,
  66. ["<C-p>"] = actions.move_selection_previous,
  67. ["<C-q>"] = actions.smart_send_to_qflist + actions.open_qflist,
  68. -- ["<c-t>"] = trouble.open_with_trouble,
  69. -- ["<C-i>"] = my_cool_custom_action,
  70. },
  71. },
  72. },
  73. extensions = {
  74. fzy_native = {
  75. override_generic_sorter = false,
  76. override_file_sorter = true,
  77. },
  78. },
  79. })
  80. end
  81. function M.find_lunarvim_files(opts)
  82. opts = opts or {}
  83. local themes = require "telescope.themes"
  84. local theme_opts = themes.get_ivy {
  85. previewer = false,
  86. sorting_strategy = "ascending",
  87. layout_strategy = "bottom_pane",
  88. layout_config = {
  89. height = 5,
  90. width = 0.5,
  91. },
  92. prompt = ">> ",
  93. prompt_title = "~ LunarVim files ~",
  94. cwd = CONFIG_PATH,
  95. find_command = { "git", "ls-files" },
  96. }
  97. opts = vim.tbl_deep_extend("force", theme_opts, opts)
  98. require("telescope.builtin").find_files(opts)
  99. end
  100. function M.grep_lunarvim_files(opts)
  101. opts = opts or {}
  102. local themes = require "telescope.themes"
  103. local theme_opts = themes.get_ivy {
  104. sorting_strategy = "ascending",
  105. layout_strategy = "bottom_pane",
  106. prompt = ">> ",
  107. prompt_title = "~ search LunarVim ~",
  108. cwd = CONFIG_PATH,
  109. }
  110. opts = vim.tbl_deep_extend("force", theme_opts, opts)
  111. require("telescope.builtin").live_grep(opts)
  112. end
  113. function M.setup()
  114. local telescope = require "telescope"
  115. telescope.setup(lvim.builtin.telescope)
  116. if lvim.builtin.project.active then
  117. telescope.load_extension "projects"
  118. end
  119. if lvim.builtin.telescope.on_config_done then
  120. lvim.builtin.telescope.on_config_done(telescope)
  121. end
  122. end
  123. return M