fzf.lua 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. local M = {
  2. "ibhagwan/fzf-lua",
  3. }
  4. M.config = function()
  5. local fzf_lua = require("fzf-lua")
  6. -- Basic fzf-lua setup
  7. fzf_lua.setup({
  8. layout = "fzf-vim",
  9. keymap = {
  10. fzf = {
  11. ["CTRL-Q"] = "select-all+accept",
  12. },
  13. },
  14. grep = {
  15. fzf_opts = {
  16. ["--history"] = vim.fn.stdpath("data") .. "/fzf-lua-grep-history",
  17. },
  18. },
  19. })
  20. nmap("gd", function()
  21. fzf_lua.lsp_definitions({ jump1 = true })
  22. end, { desc = "Goto Definition" })
  23. nmap("gr", function()
  24. fzf_lua.lsp_references({ ignore_current_line = true })
  25. end, { desc = "Goto References" })
  26. nmap("gi", function()
  27. fzf_lua.lsp_implementations({ jump1 = true })
  28. end, { desc = "Goto Implementation" })
  29. nmap("<leader>D", fzf_lua.lsp_typedefs, { desc = "Type Definition" })
  30. nmap("<leader>ca", fzf_lua.lsp_code_actions, { desc = "Code Action" })
  31. nmap("<leader>ds", fzf_lua.lsp_document_symbols, { desc = "Document Symbols" })
  32. nmap("<leader>ic", fzf_lua.lsp_incoming_calls, { desc = "Incoming Calls" })
  33. nmap("<leader>oc", fzf_lua.lsp_outgoing_calls, { desc = "Outgoing Calls" })
  34. nmap("<leader>gf", fzf_lua.live_grep, { desc = "Find Live Grep" })
  35. local exclusions = {
  36. "node_modules",
  37. ".git",
  38. "dist",
  39. "build",
  40. "coverage",
  41. "public",
  42. }
  43. local exclude_opts = ""
  44. for _, item in ipairs(exclusions) do
  45. exclude_opts = exclude_opts .. " --exclude " .. item
  46. end
  47. nmap("<leader>/", function()
  48. fzf_lua.files({
  49. cwd_prompt = false,
  50. silent = true,
  51. fd_opts = "--hidden --no-ignore --type f" .. exclude_opts,
  52. })
  53. end, { desc = "Find Files" })
  54. nmap(";", fzf_lua.buffers, { desc = "Find Buffers" })
  55. nmap("sb", fzf_lua.grep_curbuf, { desc = "Search Current Buffer" })
  56. nmap("gw", fzf_lua.grep_cword, { desc = "Search word under cursor" })
  57. nmap("gW", fzf_lua.grep_cWORD, { desc = "Search WORD under cursor" })
  58. nmap("sk", fzf_lua.keymaps, { desc = "Search Keymaps" })
  59. nmap("sh", fzf_lua.help_tags, { desc = "Search help" })
  60. -- Automatic sizing of height/width of vim.ui.select
  61. fzf_lua.register_ui_select(function(_, items)
  62. local min_h, max_h = 0.60, 0.80
  63. local h = (#items + 4) / vim.o.lines
  64. if h < min_h then
  65. h = min_h
  66. elseif h > max_h then
  67. h = max_h
  68. end
  69. return { winopts = { height = h, width = 0.80, row = 0.40 } }
  70. end)
  71. end
  72. return M