autopairs.lua 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. -- if not package.loaded['nvim-autopairs'] then
  2. -- return
  3. -- end
  4. local status_ok, autopairs = pcall(require, "nvim-autopairs")
  5. if not status_ok then
  6. return
  7. end
  8. local npairs = require "nvim-autopairs"
  9. local Rule = require "nvim-autopairs.rule"
  10. -- skip it, if you use another global object
  11. _G.MUtils = {}
  12. vim.g.completion_confirm_key = ""
  13. MUtils.completion_confirm = function()
  14. if vim.fn.pumvisible() ~= 0 then
  15. if vim.fn.complete_info()["selected"] ~= -1 then
  16. return vim.fn["compe#confirm"](npairs.esc "<cr>")
  17. else
  18. return npairs.esc "<cr>"
  19. end
  20. else
  21. return npairs.autopairs_cr()
  22. end
  23. end
  24. if package.loaded["compe"] then
  25. require("nvim-autopairs.completion.compe").setup {
  26. map_cr = true, -- map <CR> on insert mode
  27. map_complete = true, -- it will auto insert `(` after select function or method item
  28. }
  29. end
  30. npairs.setup {
  31. check_ts = true,
  32. ts_config = {
  33. lua = { "string" }, -- it will not add pair on that treesitter node
  34. javascript = { "template_string" },
  35. java = false, -- don't check treesitter on java
  36. },
  37. }
  38. require("nvim-treesitter.configs").setup { autopairs = { enable = true } }
  39. local ts_conds = require "nvim-autopairs.ts-conds"
  40. -- press % => %% is only inside comment or string
  41. npairs.add_rules {
  42. Rule("%", "%", "lua"):with_pair(ts_conds.is_ts_node { "string", "comment" }),
  43. Rule("$", "$", "lua"):with_pair(ts_conds.is_not_ts_node { "function" }),
  44. }