init.lua 1.3 KB

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