telescope.lua 4.0 KB

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