autopairs.lua 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. local M = {}
  2. function M.config()
  3. lvim.builtin.autopairs = {
  4. active = true,
  5. on_config_done = nil,
  6. ---@usage modifies the function or method delimiter by filetypes
  7. map_char = {
  8. all = "(",
  9. tex = "{",
  10. },
  11. ---@usage check bracket in same line
  12. enable_check_bracket_line = false,
  13. ---@usage check treesitter
  14. check_ts = true,
  15. ts_config = {
  16. lua = { "string", "source" },
  17. javascript = { "string", "template_string" },
  18. java = false,
  19. },
  20. disable_filetype = { "TelescopePrompt", "spectre_panel" },
  21. ---@usage disable when recording or executing a macro
  22. disable_in_macro = false,
  23. ---@usage disable when insert after visual block mode
  24. disable_in_visualblock = false,
  25. disable_in_replace_mode = true,
  26. ignored_next_char = string.gsub([[ [%w%%%'%[%"%.] ]], "%s+", ""),
  27. enable_moveright = true,
  28. ---@usage add bracket pairs after quote
  29. enable_afterquote = true,
  30. ---@usage trigger abbreviation
  31. enable_abbr = false,
  32. ---@usage switch for basic rule break undo sequence
  33. break_undo = true,
  34. map_cr = true,
  35. ---@usage map the <BS> key
  36. map_bs = true,
  37. ---@usage map <c-w> to delete a pair if possible
  38. map_c_w = false,
  39. ---@usage Map the <C-h> key to delete a pair
  40. map_c_h = false,
  41. ---@usage change default fast_wrap
  42. fast_wrap = {
  43. map = "<M-e>",
  44. chars = { "{", "[", "(", '"', "'" },
  45. pattern = string.gsub([[ [%'%"%)%>%]%)%}%,] ]], "%s+", ""),
  46. offset = 0, -- Offset from pattern match
  47. end_key = "$",
  48. keys = "qwertyuiopzxcvbnmasdfghjkl",
  49. check_comma = true,
  50. highlight = "Search",
  51. highlight_grey = "Comment",
  52. },
  53. }
  54. end
  55. M.setup = function()
  56. local status_ok, autopairs = pcall(require, "nvim-autopairs")
  57. if not status_ok then
  58. return
  59. end
  60. autopairs.setup {
  61. check_ts = lvim.builtin.autopairs.check_ts,
  62. enable_check_bracket_line = lvim.builtin.autopairs.enable_check_bracket_line,
  63. ts_config = lvim.builtin.autopairs.ts_config,
  64. disable_filetype = lvim.builtin.autopairs.disable_filetype,
  65. disable_in_macro = lvim.builtin.autopairs.disable_in_macro,
  66. ignored_next_char = lvim.builtin.autopairs.ignored_next_char,
  67. enable_moveright = lvim.builtin.autopairs.enable_moveright,
  68. enable_afterquote = lvim.builtin.autopairs.enable_afterquote,
  69. map_c_w = lvim.builtin.autopairs.map_c_w,
  70. map_bs = lvim.builtin.autopairs.map_bs,
  71. disable_in_visualblock = lvim.builtin.autopairs.disable_in_visualblock,
  72. fast_wrap = lvim.builtin.autopairs.fast_wrap,
  73. }
  74. if lvim.builtin.autopairs.on_config_done then
  75. lvim.builtin.autopairs.on_config_done(autopairs)
  76. end
  77. pcall(function()
  78. local function on_confirm_done(...)
  79. require("nvim-autopairs.completion.cmp").on_confirm_done()(...)
  80. end
  81. require("cmp").event:off("confirm_done", on_confirm_done)
  82. require("cmp").event:on("confirm_done", on_confirm_done)
  83. end)
  84. end
  85. return M