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.

74 lines
2.2 KiB

  1. local pickers = require("telescope.pickers")
  2. local finders = require("telescope.finders")
  3. local previewers = require("telescope.previewers")
  4. local action_state = require("telescope.actions.state")
  5. local conf = require("telescope.config").values
  6. local actions = require("telescope.actions")
  7. require("telescope").setup({
  8. defaults = {
  9. file_sorter = require("telescope.sorters").get_fzy_sorter,
  10. prompt_prefix = " >",
  11. color_devicons = true,
  12. file_previewer = require("telescope.previewers").vim_buffer_cat.new,
  13. grep_previewer = require("telescope.previewers").vim_buffer_vimgrep.new,
  14. qflist_previewer = require("telescope.previewers").vim_buffer_qflist.new,
  15. mappings = {
  16. i = {
  17. ["<C-x>"] = false,
  18. ["<C-q>"] = actions.send_to_qflist,
  19. },
  20. },
  21. },
  22. })
  23. local M = {}
  24. function git_branches ()
  25. require("telescope.builtin").git_branches({
  26. attach_mappings = function(_, map)
  27. map("i", "<c-d>", actions.git_delete_branch)
  28. map("n", "<c-d>", actions.git_delete_branch)
  29. return true
  30. end,
  31. })
  32. end
  33. function files ()
  34. local ran, errorMessage = pcall(function()
  35. require('telescope.builtin').git_files({ show_untracked = true })
  36. end)
  37. if not ran then
  38. require('telescope.builtin').find_files()
  39. end
  40. end
  41. local options = { noremap = true }
  42. vim.keymap.set('n', '<C-g>', require('telescope.builtin').live_grep, options)
  43. vim.keymap.set('n', '<C-p>', files, options)
  44. vim.keymap.set('n', '<A-p>', function()
  45. require('telescope.builtin').find_files()
  46. end, options)
  47. vim.keymap.set('n', '<leader>df', function()
  48. require("telescope.builtin").find_files({
  49. prompt_title = "< VimRC >",
  50. cwd = vim.fn.expand('~/.config/nvim'),
  51. hidden = true,
  52. })
  53. end, options)
  54. vim.keymap.set('n', '<leader>fb', require('telescope.builtin').buffers, options)
  55. vim.keymap.set('n', '<leader>fo', require('telescope.builtin').oldfiles, options)
  56. vim.keymap.set('n', 'gr', require('telescope.builtin').lsp_references, options)
  57. vim.keymap.set('n', '<leader>m', require('telescope.builtin').marks, options)
  58. vim.keymap.set('n', '<leader>ch', require('telescope.builtin').command_history, options)
  59. vim.keymap.set('n', '<leader>gb', git_branches, options)
  60. vim.keymap.set('n', '<leader>gs', require('telescope.builtin').git_status, options)