telescope.lua 4.0 KB

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